Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You shoud use the attribute <code>href</code> instead, also note that .NET is case-sensitive by default</p> <pre><code>For Each link As HtmlNode In htmlDoc.DocumentNode.SelectNodes("//a[@href]") Dim href = link.Attributes("href").Value If href.IndexOf("test", StringComparison.OrdinalIgnoreCase) &gt;= 0 Then ListBox1.Items.Add(href) ' or ListBox1.Items.Add(link.InnerText) End If Next </code></pre> <p>Here is a method that should return all links in a document as <code>List(Of Link)</code>. <code>Link</code> is a custom class with two perties, one for the text and the other for the <code>Uri</code>:</p> <pre><code>Public Class Link Public Sub New(Uri As Uri, Text As String) Me.Uri = Uri Me.Text = Text End Sub Public Property Text As String Public Property Uri As Uri Public Overrides Function ToString() As String Return String.Format("{0} [{1}]", Text, If(Uri Is Nothing, "", Uri.ToString())) End Function End Class Public Function GetLinks(doc As HtmlAgilityPack.HtmlDocument) As List(Of Link) Dim uri As Uri = Nothing Dim linksOnPage = From link In doc.DocumentNode.Descendants() Where link.Name = "a" _ AndAlso link.Attributes("href") IsNot Nothing _ Let text = link.InnerText.Trim() Let url = link.Attributes("href").Value Where uri.TryCreate(url, UriKind.Absolute, uri) Dim Uris As New List(Of Link)() For Each link In linksOnPage Uris.Add(New Link(New Uri(link.url, UriKind.Absolute), link.text)) Next Return Uris End Function </code></pre> <p>Here is the requested overload that checks if an url contains a given text:</p> <pre><code>Public Function GetLinks(doc As HtmlAgilityPack.HtmlDocument, linkContains As String) As List(Of Link) Dim uri As Uri = Nothing Dim linksOnPage = From link In doc.DocumentNode.Descendants() Where link.Name = "a" _ AndAlso link.Attributes("href") IsNot Nothing _ Let text = link.InnerText.Trim() Let url = link.Attributes("href").Value Where url.IndexOf(linkContains, StringComparison.OrdinalIgnoreCase) &gt;= 0 _ AndAlso uri.TryCreate(url, UriKind.Absolute, uri) Dim Uris As New List(Of Link)() For Each link In linksOnPage Uris.Add(New Link(New Uri(link.url, UriKind.Absolute), link.text)) Next Return Uris End Function </code></pre> <p><strong>Edited</strong> now tested, works, use it in the following way:</p> <pre><code>Dim site = File.ReadAllText("C:\Temp\website_test.htm") Dim doc = New HtmlAgilityPack.HtmlDocument() doc.LoadHtml(site) Dim links = GetLinks(doc) For Each Link In links ListBox1.Items.Add(Link.ToString()) Next </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload