如何从网站中提取特定文本块

发布于 2024-09-13 15:03:04 字数 82 浏览 0 评论 0原文

我必须从网络中提取有用的信息

我可以使用 C#

示例

标题:abc

我只得到“abc”

i have to extract useful information from web

i can i do using c#

example

title: abc

i have get only "abc"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

明月夜 2024-09-20 15:03:52

使用 DOM 解析器您可以提取所需的元素。如果您预先知道块 ID 或者您能够准备好它,那么提取就非常简单。

Using DOM parser you can extract required elements. If you pre-aware of the block id or if you able to prepare it then the extraction is quite simple.

太阳公公是暖光 2024-09-20 15:03:36

如果您需要从网站中提取文本,则需要使用 HTML 解析器,例如 HTML Agility Pack

If you need to extract text from a website, you need to use an HTML parser such as the HTML Agility Pack.

娇俏 2024-09-20 15:03:18

正如 @Oded 所建议的,Html Agility Pack 将很有用。

这是 html 敏捷包的示例。

 HtmlDocument doc = new HtmlDocument();
 doc.Load("file.htm");
 foreach(HtmlNode link in doc.DocumentElement.SelectNodes("//a[@href"])
 {
    HtmlAttribute att = link["href"];
    att.Value = FixLink(att);
 }
 doc.Save("file.htm");

As, @Oded♦ recommended, Html Agility Pack will be useful.

This is example of html agility pack.

 HtmlDocument doc = new HtmlDocument();
 doc.Load("file.htm");
 foreach(HtmlNode link in doc.DocumentElement.SelectNodes("//a[@href"])
 {
    HtmlAttribute att = link["href"];
    att.Value = FixLink(att);
 }
 doc.Save("file.htm");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文