0

I'm trying to get URLs from within an external webpage using a macro. Here's my current code:

Sub GoToWebSite()

Dim IE As Object

Application.ScreenUpdating = False

Set IE = CreateObject("InternetExplorer.Application")

With IE

    .Navigate "www.website.com/careers/"

    .Visible = True
End With

Application.ScreenUpdating = True 
Set IE = Nothing

End Sub

From here, I want to supply the macro with a particular URL, tell it to search for particular text within www.website.com/careers/, then tell it to grab the hyperlink corresponding to the text, and paste the hyperlink in a cell in a spreadsheet. So for example, search for "Sales" then paste the URL corresponding to "Sales" in a particular cell.

Bond
  • 16,071
  • 6
  • 30
  • 53
xxxRxxx
  • 357
  • 2
  • 7
  • 17
  • please check if one of the already existing answer is answering what you are searching for, perhaps http://stackoverflow.com/questions/27066963/scraping-data-from-website-using-vba already does – Marged Aug 24 '15 at 21:27

1 Answers1

0

There's no way to select an element based on its innerText, so you'll need to iterate the anchor/links node list and check each to see if it's the one you're looking for.

For example:

Dim objLink

For Each objLink in IE.document.getElementsByTagName("a")
    If StrComp(objLink.innerText, "sales", vbTextCompare) = 0 Then

        ' Found the link matching our text. Display its URL...
        Debug.Print objLink.href
        Exit For

    End If
Next
Bond
  • 16,071
  • 6
  • 30
  • 53