PDA

View Full Version : Copy specific links into excel from explorer html



nemaded
12-01-2016, 01:45 AM
Hi,

I have created macro which copy links from HTML and paste in excel sheet. I need specific links to selected and others to be ignored. Below is the sample of HTML code and VBA which I have created. Can anybody please help me so that I can select specific links

From below HTML, I need links to be selected if h2 class="post-box-title"

==========================
<article class="item-list">

<h2 class="post-box-title">
<a href="/upsc-recruitment-2016-17-notification-12-economics-officer-posts/">UPSC recruitment 2016-17 notification 12 economics officer posts</a>
</h2>

<p class="post-meta">
===========================




Below is the VBA Code which selects all link.

===========================
Sub Button1_Click()
Dim IE As Object
Dim doc, element
Dim doc1, element1
Dim doc2, element2
Dim IEDoc
Dim d As Variant
Dim e As Variant
Dim f As Variant


Dim ElementCol As Object
Dim Link As Object
Dim erow As Long


Set objWSS = CreateObject("WScript.Shell")
Set IE = CreateObject("InternetExplorer.Application")

With IE
.Visible = True
.navigate "http link"

Application.StatusBar = "Trying to go to website…"
DoEvents
'Loop
Set html = IE.document
'Display text of HTML document returned in a cell
Range("A1") = html.DocumentElement.innerHTML
Set ElementCol = html.getElementsByTagName("a")


'--------------------------------
For Each Link In ElementCol


erow = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Cells(erow, 1).Value = Link
Cells(erow, 1).Columns.AutoFit


Next
'close down IE, reset status bar & turn on screenupdating
Set IE = Nothing
Application.StatusBar = ""
Application.ScreenUpdating = True




End With
End Sub



===========================