2016-01-06 90 views
0

問題一:

我有一個與特定內容中提取網頁(WebSource)的URL的程序(/articles/過濾器使用htmlagility提取鏈接從網頁 - vb.net

Dim links As New List(Of String)() 
Dim htmlDoc As New HtmlAgilityPack.HtmlDocument() 
htmlDoc.LoadHtml(WebSource) 
For Each link As HtmlNode In htmlDoc.DocumentNode.SelectNodes("//a[@href]") 
    Dim att As HtmlAttribute = link.Attributes("href") 
    If att.Value.Contains("/articles/") Then 
     links.Add(att.Value) 
    End If 
Next 

是它可能的網址進行查詢,並用兩個值進行篩選,例如在科技網站我想找到所有網址都包含/articles/LG

問題二:

提取的URL是不完整的HTTP地址例如我的結果之一是

/articles/car 

而是完整地址,例如

http://website.com/articles/car 

的我怎樣才能解決這個問題?

回答

1

您正在檢查ONE內容現在。用於檢查多個項目的htmlagility中,您可以使用多個if聲明如下

If att.Value.Contains("content1") Then 
    If att.Value.Contains("content2") Then 
     If att.Value.Contains("content3") Then 
      links.Add(att.Value) 
     End If 
    End If 
End If 
+1

:字符串?沒有。如果我使用'「/ articles /」&「LG」'實際上我使用'「/ articles/LG」'。你知道什麼關於字符串????????? –

+0

抱歉的男人.... @ArashHatami後修改 – 2016-01-07 14:55:51

+1

這太愚蠢了!爲什麼我的思想不是......非常感謝你 –