用替代文本 html 敏捷包替换图像
我需要解析图像的 HTML 并用一个新标签替换这些标签,该新标签只包含替换中包含的文本。有人可以展示如何使用 linq 和标准用法来做到这一点吗?
我现在使用 linq 示例来替换段落。但是,我收到只读错误。
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(html);
IEnumerable<HtmlNode> paragraphs = doc.DocumentNode.DescendantNodes().Where(p => p.Name.ToLower() == "p");
foreach (HtmlNode p in paragraphs)
{
p.InnerText = "Hello World";
}
还有一种简单的方法可以将其转回文本吗?即输出为字符串
这是我所拥有的不起作用
MemoryStream outStream = new MemoryStream();
doc.Save(outStream);
outStream.Seek(0, SeekOrigin.Begin);
StreamReader reader = new StreamReader( outStream );
string text = reader.ReadToEnd();
I need to parse HTML for images and replace those tags with a new tag that just has the text that is contained in the alternate. Can someone show how to do this with both linq and standard usage?
I've using a linq sample now to replace paragraphs. But, I'm getting a read only error.
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(html);
IEnumerable<HtmlNode> paragraphs = doc.DocumentNode.DescendantNodes().Where(p => p.Name.ToLower() == "p");
foreach (HtmlNode p in paragraphs)
{
p.InnerText = "Hello World";
}
Also is there an easy way to transfer it back to text? I.e Output as string
This is what I have which doesn't work
MemoryStream outStream = new MemoryStream();
doc.Save(outStream);
outStream.Seek(0, SeekOrigin.Begin);
StreamReader reader = new StreamReader( outStream );
string text = reader.ReadToEnd();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)