1

I'm trying to extract a specific link from a website and I'm having trouble pulling into a String.

The link to the source code is this: view-source:http://finder.fi/yrityshaku/Nokia+oyj this is the part I'm looking at:

<div class="itemName">





      <!-- Yritysnimi -->

        <!-- Aukeaa aina yhteystiedot-vÃ?lilehdelle -->
        <a href="/Tietoliikennepalveluja%2C+tietoliikennelaitteita/Nokia+Oyj/TAMPERE/yhteystiedot/159838" class="resultGray">

I want to extract the Substring:

/Tietoliikennepalveluja%2C+tietoliikennelaitteita/Nokia+Oyj/TAMPERE/yhteystiedot/159838

I've tried to use browserIE.Document.body.innerText but it seems to only copy parts of the source code that are plain text on the original website.

I've researched some but I haven't found a suitable solution yet. Some have suggested pulling just an element from the source code and others copying the whole source code into a string variable. As a person who's not too expert in vba I'd prefer pulling the whole code into a string as I think this way would be easier to understand.

Original website (in finnish) http://finder.fi/yrityshaku/nokia+oyj

A BIG THANK YOU in advance!

Joonas
  • 177
  • 1
  • 2
  • 8
  • Have you seen this: http://stackoverflow.com/questions/25488687/parse-html-content-in-vba ? –  Dec 22 '15 at 14:53

1 Answers1

0

How about this:

Sub ExtractLink()

Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")

With IE

    .Navigate "http://finder.fi/yrityshaku/nokia+oyj"

    Do
        DoEvents
    Loop While .Busy Or .Readystate <> 4

    .Visible = True

    Dim oDoc As Object
    Set oDoc = .document

    With oDoc

        Dim cLinks As Object, iLink As Object, sText As String
        sText = "Tietoliikennepalveluja%2C+tietoliikennelaitteita/Nokia+Oyj/TAMPERE"

        Set cLinks = .links

        For Each iLink In cLinks

            If InStr(1, iLink.Href, sText) Then

                Debug.Print Replace(iLink.Href, "http://finder.fi", "")

            End If

        Next

    End With

End With

End Sub
Scott Holtzman
  • 27,099
  • 5
  • 37
  • 72
  • Thank you for the quick reply. I just realized I didn't ask the question clear enough, I have about 30 000 companies I need to search and all of their links are different.Thus I don't know what the substring I'm extracting is going to be. I only know what the substrings around the link I'm extracting are - as they are the same every time. Sorry about the mistake. – Joonas Jan 04 '16 at 12:33