2016-07-22 89 views
0

我正在從網頁上的圖像提取軟件工作。已經創建了一個功能圖像提取:uri太長

public static void GetAllImages() 
     { 

      WebClient x = new WebClient(); 
      string source = x.DownloadString(@"http://www.bbc.com"); 

      var document = new HtmlWeb().Load(source); 
      var urls = document.DocumentNode.Descendants("img") 
           .Select(e => e.GetAttributeValue("src", null)) 
           .Where(s => !String.IsNullOrEmpty(s)); 

      document.Load(source); 


     } 

它說:「URI過長」 ..

我試圖用Uri.EscapeDataString。但沒有得到知道在哪裏把它

任何幫助,將讚賞

+0

凡/時,它說,烏里太長? – Richard

+0

on var document = new HtmlWeb()。Load(source); –

+0

我敢打賭,HtmlWeb.Load將Uri作爲其參數,同時爲您提供整個頁面內容。 也請爲您的問題添加HtmlWeb類的描述。你可能正在使用一些第三方庫。 –

回答

1

HtmlWeb.Load需要一個URL作爲其來源和處理內容的下載。你不需要補充WebClient來做到這一點,這一切都照顧。

你正在做的是下載內容,然後嘗試使用下載的內容(HTML)作爲URL(可能在Load意味着Parse的假設下)。

所以刪除

WebClient x = new WebClient(); 
string source = x.DownloadString(@"http://www.bbc.com"); 

然後下一行更改爲

var document = new HtmlWeb().Load(@"http://www.bbc.com"); 

,你會好到哪裏去。