【问题标题】:Cannot retrieve html from website无法从网站检索 html
【发布时间】:2014-10-05 00:08:07
【问题描述】:

我正在我的 WebBrowser 中加载这个 page [可能是 NSFW] 当 WebBrowser.ReadyState 准备就绪时,我尝试在 WebBrowser.Document.DomDocument、WebBrowser.Document.Body.InnerHtml、WebBrowser.Document.Body.OuterHtml 中查看,但不是我在 WebBrowser 中看到的页面。

WebBrowser b = new WebBrowser();
b.Navigate(url);
WaitBrowserLoading(b); //wait browser to complete loading
MessageBox.Show(b.Document.Body.OuterHtml);    
MessageBox.Show(b.Document.Body.InnerHtml);

最后两个函数都不会返回我在使用 Chrome 分析时可以看到的页面。

有什么建议吗?

【问题讨论】:

  • 我们如何在没有看到您正在使用的代码的情况下提出任何建议?
  • 您看到的区别是什么;你希望看到什么?在不知道你期待什么的情况下,很难回答。
  • @AdrianWragg 尝试在您的浏览器中加载页面,并获取 html。然后将其与 b.Document.Body.OuterHtml 或 b.Document.Body.OuterHtml 进行比较,这两个函数应该返回您从浏览器获取的相同 html
  • 这是一个糟糕的示例页面;你看那个是有原因的吗?另外,您是使用 Chrome 的浏览器工具还是只是“查看源代码”?
  • @AdrianWragg 我需要获取该页面的 html,这不是示例。我正在使用 chrome 的工具,所以我需要类似的工具

标签: c# html dom browser domdocument


【解决方案1】:

正确的结果是在 webBrowser.Document.GetElementsByTagName("HTML")[0].OuterHtml

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多