shahin
Active Member
Hi there!! Hope you all are doing well. This time I've got stuck on a slightly different issue with my script. The script is supposed to find "contact" or "about" link from some webpages stored within "linklists" variable. It is doing it's job not following the condition I tried to create. I expected my script parse the link connected to "contact" and If "contact" is not available then only it will look for "about" link to parse. However, when both of the "contact" and "about" link are available, the scraper sources the link connected to "about" whereas my initial and main condition is to get link connected to "contact". How can I create the condition in such a way so the script will first look for "contact" link and If "contact" link is not available then it will go for parsing "about" link.
This is what i have tried so far:
Btw, If I comment out the below portion from my above script then the script does parse the "contact" link from each webpage but I would like to keep both the conditions active within my script so that if one is missing another will be of use.
This is what i have tried so far:
Code:
Sub Get_Conditional_Links()
Dim IE As New InternetExplorer, HTML As HTMLDocument, post As Object
Dim newlink As String, linklists As Variant, link As Variant
linklists = [{"http://www.mount-zion.biz/","http://www.innovaprint.com.sg/","http://www.cityscape.com.sg/"}]
For Each link In linklists
With IE
.Visible = True
.navigate link
While .Busy = True Or .readyState < 4: DoEvents: Wend
Set HTML = .document
End With
For Each post In HTML.getElementsByTagName("a")
If InStr(1, post.innerText, "contact", 1) > 0 Then
newlink = post.getAttribute("href")
Exit For
ElseIf InStr(1, post.innerText, "about", 1) > 0 Then
newlink = post.getAttribute("href")
Exit For
End If
Next post
R = R + 1: Cells(R, 1) = newlink
Next link
IE.Quit
End Sub
Btw, If I comment out the below portion from my above script then the script does parse the "contact" link from each webpage but I would like to keep both the conditions active within my script so that if one is missing another will be of use.
Code:
ElseIf InStr(1, post.innerText, "about", 1) > 0 Then
newlink = post.getAttribute("href")
Exit For