我尝试取消 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/