HttpClient没有';无法获取完整的网站html源代码
本文关键字:网站 源代码 html 获取 没有 HttpClient | 更新日期: 2024-09-21 22:03:53
我试图取消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
结果长度为46476。
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;" });
}