【问题标题】:I can't get the content of a web page without html codes in C#没有 C# 中的 html 代码,我无法获取网页的内容
【发布时间】:2017-12-23 10:28:36
【问题描述】:

我想在 windows 窗体应用程序 中获取网页的文本。我正在使用:

WebClient client = new WebClient();
string downloadString = client.DownloadString(link);

但是,它给了我网页的html代码。 问题来了:

我可以获得网站的特定部分吗?例如具有类名 “ask-page new-topbar” 的部件。我想获取类名 "ask-page new-topbar" 的每个部分。

【问题讨论】:

  • 您可以手动执行此操作,也可以在使用上述方法检索到HtmlDocument 后将其加载到HtmlDocument 中。您必须先检索它,没有任何东西只会检索 html 文档的一部分。

标签: c# html webclient windows-forms-designer


【解决方案1】:

不,当您向 url 发送请求时,您不能只获取网站的部分内容。

您可以做的是使用Html Agility Pack 并让它挖掘 Html 代码,为您提供所请求节点的内容。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-22
    • 2021-12-03
    • 1970-01-01
    • 2014-08-16
    • 2012-02-27
    相关资源
    最近更新 更多