2016-01-09 46 views
1

我需要从网站阅读所有视频网址。如何使用HtmlAgilityPack阅读它。我已经尝试过这样的,但它不是working.Here是我的代码如何使用HtmlAgilityPack从网站阅读视频网址

var document = new HtmlWeb().Load("http://www.example.com/"); 
    var urls = document.DocumentNode.Descendants("img[src$='.mp4']") 
      .Select(e => e.GetAttributeValue("src", null)) 
      .Where(s => !String.IsNullOrEmpty(s)).ToList(); 

回答

0

尝试以下操作:

var urls = document.DocumentNode 
    .Descendants("img") 
    .Where(d => d.Attributes["src"].Value.EndsWith(".mp4")) 
    .Select(d => d.Attributes["src"].Value); 

从所有img标签,只有那些在mp4结束src值被考虑。

+0

没有它没有工作。我正在通过此页面阅读YouTube视频http://www.volvocars.com/us/cars/new-models/s60 – bala3569

+0

我访问过提供的URL - > view source - >找不到包含mp4的任何内容。如果该元素是异步加载的,则在获取文档时将无法使用该元素。 – Alexei