Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 将刮取的web链接存储到阵列中_Arrays_Vb.net - Fatal编程技术网

Arrays 将刮取的web链接存储到阵列中

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

我正在尝试将刮取的web链接存储到数组中,以便以后在代码中使用它们。我有VBScript解决方案,并试图将其转换为VB.net,但没有结果。谁能给我个暗示吗

在VBScript中,我使用vbCrLf分离链接

我想在这个阶段存储链接并将它们打印到控制台以确保安全

这是我目前的代码:

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