2

I have a written a program which downloads a webpage's source but now I want to search the source for a particular link I know the link is written like this:

<a href="/internet/A2/"><b>Geographical Survey Work</b></a>

Is there anyway of using "Geographical Survey Work" as criteria to retrieve the link? The code I am using to download the source to a string is this:

Dim sourcecode As String = ((New Net.WebClient).DownloadString("http://examplesite.com"))

So just to clarify I want to type into an input box "Geographical Survey Work" for instance and "/internet/A2" to popup in a messagebox? I think it can be done using a regex, but that's a bit beyond me. Any help would be great.

4

1 に答える 1

0

HTMLAgilityPack の場合:

Dim vsPageHTML As String = "<html>... your webpage HTML code ...</html>"
Dim voHTMLDoc.LoadHtml(vsPageHTML) : vsPageHTML = ""
Dim vsURI As String = ""
Dim voNodes As HtmlAgilityPack.HtmlNodeCollection = voHTMLDoc.SelectNodes("//a[@href]")
If Not IsNothing(voNodes) Then
    For Each voNode As HtmlAgilityPack.HtmlNode In voNodes
        If voNode.innerHTML.toLower() = "<b>geographical survey work</b>" Then
            vsURI = voNode.GetAttributeValue("href", "")
            Exit For
        End If
    Next
End If
voNodes = Nothing : voHTMLDoc = Nothing

vsURI でやりたいことが何でもできます。私はフリーハンドで書いているので、コードを少し調整する必要があるかもしれません。

于 2012-12-24T17:42:21.363 に答える