如何更改CsQuery
大家好imageTag SRC路径如何更改所有图片“src”用户在CSQuery
一个HTML字符串这里是我的代码如何更改CsQuery
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;
}
}
回答:
这个工作对我来说
CQ HtmlContainingImg = html; foreach (var img in HtmlContainingImg["IMG"])
{
string imgsrc = img.Attributes["src"];
if (!IsAbsoluteUrl(imgsrc))
{
img.Attributes["src"]= Setting.FelApplicationPath + Setting.folderPath + imgsrc;
}
}
html= HtmlContainingImg.Render(); // I was missing this line
回答:
尝试 img.SetAttribute(“src”用户, Setting.FelApplicationPath + Setting.folderPath + imgsrc);
以上是 如何更改CsQuery 的全部内容, 来源链接: utcz.com/qa/265390.html