【发布时间】:2019-11-23 12:09:29
【问题描述】:
我想获取所有包含/product/ 的链接。有 17 个链接包含 /product/。该怎么做?
这行好像有问题
Dim srcs = From iframeNode In htmlDoc.DocumentNode.SelectNodes("//a[@href]")
Select iframeNode.Attributes("href").Value
如何添加参数以通过/product/过滤?
这是我目前所拥有的:
Imports HtmlAgilityPack
Module Module1
Sub Main()
Dim mainUrl As String = "https://www.nordicwater.com/products/waste-water/"
Dim htmlDoc As New HtmlAgilityPack.HtmlDocument
htmlDoc.LoadHtml(mainUrl)
Dim srcs = From iframeNode In htmlDoc.DocumentNode.SelectNodes("//a[@href]")
Select iframeNode.Attributes("href").Value
'print all the src you got
For Each src In srcs
Console.WriteLine(src)
Next
End Sub
End Module
编辑:
工作解决方案:
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 srcs As HtmlNodeCollection = htmlDoc.DocumentNode.SelectNodes("//ul[@class='products-list-page']//a") '< - - - select nodes with links
For Each src As HtmlNode In srcs
Console.WriteLine(src.Attributes("href").Value) '< - - - Print urls
Next
Console.Read()
End Sub
End Module
【问题讨论】:
标签: vb.net web-scraping web-crawler html-agility-pack