从网页中提取图像源,其中img标签可能会在使用javascript etcq渲染页面时添加

Extract image sources from a web page, where img tags might be added when the page is rendered by javascript etcq

本文关键字:javascript etcq 添加 图像 提取 网页 标签 img 其中      更新时间:2023-09-26

我想在c#/asp.net中提取网页中所有图像的"

我正在使用:

WebClient client = new WebClient();
string mainSource = client.DownloadString(URL);

并在mainSource字符串中搜索"。

这个方法似乎可以正常工作,但只有当所有的图像("标签")都存在于网页的原始源代码中。

javascript等渲染的图像标签在上述过程中没有被扫描。

还有别的方法吗?

试试

   HtmlWeb hw = new HtmlWeb();
 HtmlDocument doc = hw.Load(/* url */);
 foreach(HtmlNode link in doc.DocumentElement.SelectNodes("//img[@src]"))
 {
 }