Arrays 将刮取的web链接存储到阵列中
我正在尝试将刮取的web链接存储到数组中,以便以后在代码中使用它们。我有VBScript解决方案,并试图将其转换为VB.net,但没有结果。谁能给我个暗示吗 在VBScript中,我使用vbCrLf分离链接 我想在这个阶段存储链接并将它们打印到控制台以确保安全 这是我目前的代码:Arrays 将刮取的web链接存储到阵列中,arrays,vb.net,Arrays,Vb.net,我正在尝试将刮取的web链接存储到数组中,以便以后在代码中使用它们。我有VBScript解决方案,并试图将其转换为VB.net,但没有结果。谁能给我个暗示吗 在VBScript中,我使用vbCrLf分离链接 我想在这个阶段存储链接并将它们打印到控制台以确保安全 这是我目前的代码: Imports HtmlAgilityPack Module Module1 Sub Main() Dim mainUrl As String = "https://www.nordicwa
Imports HtmlAgilityPack
Module Module1
Sub Main()
Dim mainUrl As String = "https://www.nordicwater.com/products/waste-water/"
Dim htmlDoc As HtmlDocument = New HtmlWeb().Load(mainUrl) '< - - - Load the webage into htmldocument
Dim LinkArrays As String ' String to store the links
Dim i As Integer = 1
Dim srcs As HtmlNodeCollection = htmlDoc.DocumentNode.SelectNodes("//ul[@class='products-list-page']//a") '< - - - select nodes with links
For Each src As HtmlNode In srcs
' Show links in console
Console.WriteLine(src.Attributes("href").Value) '< - - - Print urls
' Store links in array
LinkArrays &= src.Attributes("href").Value
i += 1
Next
Console.Read()
End Sub
End Module
可以使用数组而不是数组。使用列表中的,您可以获得一个字符串数组供以后使用:
Imports HtmlAgilityPack
Sub Main()
Dim mainUrl As String = "https://www.nordicwater.com/products/waste-water/"
Dim htmlDoc As HtmlDocument = New HtmlWeb().Load(mainUrl) '< - - - Load the webage into htmldocument
Dim listLinks As New List(Of String)
Dim srcs As HtmlNodeCollection = htmlDoc.DocumentNode.SelectNodes("//ul[@class='products-list-page']//a") '< - - - select nodes with links
For Each src As HtmlNode In srcs
' Show links in console
Console.WriteLine(src.Attributes("href").Value) '< - - - Print urls
' Store links in array
listLinks.Add(src.Attributes("href").Value)
Next
'you can get the array from the list.
Dim arrayLinks() As String = listLinks.ToArray()
Console.Read()
End Sub