【发布时间】:2015-10-04 21:31:50
【问题描述】:
for (int i = 0; i < numberoflinks; i++)
{
string downloadString = client.DownloadString(mainlink+i+".html");
var document = new HtmlWeb().Load(url);
var urls = document.DocumentNode.Descendants("img")
.Select(e => e.GetAttributeValue("src", null))
.Where(s => !String.IsNullOrEmpty(s))
}
问题是 HtmlWeb().Load 需要一个 html url,但我想加载其中已经包含 html 内容的字符串 downloadString。
更新:
我现在试过了:
for (int i = 0; i < numberoflinks; i++)
{
string downloadString = client.DownloadString(mainlink+i+".html");
HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
document.Load(downloadString);
var urls = document.DocumentNode.Descendants("img")
.Select(e => e.GetAttributeValue("src", null))
.Where(s => !String.IsNullOrEmpty(s));
}
但是我遇到了异常:
document.Load(downloadString);
路径中有非法字符
我要做的是从每个链接下载/提取所有 .JPG 图像。 无需先将 url 下载到硬盘,而是将内容下载到字符串中提取此 html 中所有以 .JPG 结尾的图像链接,然后下载 JPG。
【问题讨论】:
标签: c# .net winforms html-agility-pack