【发布时间】:2015-07-26 09:29:59
【问题描述】:
如何在 CSQuery 中更改 html 字符串中的所有图像“src”?
这是我的代码:
CQ HtmlContainingImg = html;
CQ imgTagList = HtmlContainingImg["IMG"];
foreach (var img in imgTagList)
{
string imgsrc = img.Attributes["src"];
if (!IsAbsoluteUrl(imgsrc))
{
//img.Attributes["src", Setting.FelApplicationPath + Setting.folderPath + imgsrc];// this line gives error
// even tried img.Attributes["src"]= Setting.FelApplicationPath + Setting.folderPath + imgsrc;
}
}
【问题讨论】:
-
我已经编辑了你的标题。请参阅“Should questions include “tags” in their titles?”,其中的共识是“不,他们不应该”。
-
如果它仍然在后台使用 HtmlAgilityPack,那么
imgsrc["src"].Value = "new value"应该可以解决问题