2013-11-25 31 views
3

我正在嘗試使用HTML敏捷包來讓我的程序讀取文件並從中獲取所有圖像srcs。繼承人我得到了什麼至今:c#使用html敏捷包不支持URI格式

private ArrayList GetImageLinks(String html,String link) 
    { 
     //link = url of webpage 
     //html = a string of the html, just for testing will remove after 

     HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument(); 
     htmlDoc.OptionFixNestedTags = true; 
     htmlDoc.Load(link); 
     List<String> imgs = (from x in htmlDoc.DocumentNode.Descendants() 
          where x.Name.ToLower() == "img" 
          select x.Attributes["src"].Value).ToList<String>(); 

     Console.Out.WriteLine("Hey"); 
     ArrayList imageLinks = new ArrayList(imgs); 


     foreach (String element in imageLinks) 
     { 
      Console.WriteLine(element); 

     } 

     return imageLinks; 
    } 

這是錯誤即時得到: System.ArgumentException:URI格式不被支持。

+1

在負載線上的錯誤? [**如果是這樣,那麼你應該下載內容,然後加載它,像這樣的答案。**](http://stackoverflow.com/a/10558196/342740) – Prix

+0

命名空間HtmlWeb無法找到? – R00059159

+0

https://github.com/jstedfast/HtmlAgilityPack/blob/master/HtmlAgilityPack/HtmlWeb.Xpath.cs – Prix

回答

6
HtmlDocument docHtml = new HtmlWeb().Load(url);