c# - HttpClient 没有获得完整的网站 html 源代码

标签 c# http web-scraping win-universal-app html-agility-pack

我尝试取消 http://olx.pl/ 的优惠站点,我正在使用 HttpClient,问题是从客户端检索的站点有很大不同,并且不包含优惠列表,就像直接从浏览器访问的源代码中一样。任何想法? 这是我的代码:

  string url = "http://olx.pl/oferty/q-diablo/?search%5Bdescription%5D=1";
  HttpClient client = new HttpClient();
  string result = await client.GetStringAsync(url);

最佳答案

HttpClient 不会加载从 javascript 生成的内容。相反,您可以使用将运行 js 的 WebView。我运行了两者,HttpClient 结果长度为 235507,WebView 结果长度为 464476。

    WebView wv = new WebView();
    wv.NavigationCompleted += Wv_NavigationCompleted;
    wv.Navigate(new Uri(url));

    private async void Wv_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args)
    {
        string wvresult = await sender.InvokeScriptAsync("eval", new string[] { "document.documentElement.outerHTML;" });
    }

关于c# - HttpClient 没有获得完整的网站 html 源代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36663581/

相关文章:

node.js - 在 Node 中使用 for 循环的理想方式

c# - 仅转义 XML 中 Node 的内容

c# - child 中继器的项目计数

c# - 如果数据库表更新/插入,如何让 Windows C# 控件自动更新?

c# - 为什么我们需要在 ConnectionString 中设置最小池大小

Java 套接字 HTML 响应

ruby-on-rails-3 - 导轨 : Testing OAuth API by posting multiparted messages with file attachment

http - 418 "I' m a teapot”真的是HTTP响应码吗?

python - BeautifulSoup 如何选择带有空格的 <a href> 和 <td> 元素

python - 通过 Python 抓取 Twitter 嵌入 URL