如何提取网页的动态Ajax内容 [英] How to extract dynamic ajax content from a web page

查看:144
本文介绍了如何提取网页的动态Ajax内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的要求是提取从网页所需的内容。该页面有正在被使用AJAX填充的部分。当我在网页源代码查看它没有显示用ajax加载的内容。该部分内容将改变基于选中的复选框。如果我们选择印度复选框,然后部分将显示印度的所有细节。该页面的源代码将只显示默认的内容没有使用AJAX显示的内容。我查了一下网页的源文件选中复选框后,它仍然只显示默认值。如何获得该部分内容,

My requirement is to extract the required content from a web page. The page has a section which is being populated using ajax. When i view in page source it is not showing the content loaded using ajax. The section content will change based on check box selected. If we select 'India' check box then the section will display all the details of India. The page source will show only default content not the content displayed using ajax. I checked the page source after selecting the check box, still it shows only default value. How to get that section content,

推荐答案

在C#中,您可以使用HTMLAgilityPack来嗉数据,但如果你使用webBrowser.DocumentText,你不能从网页加载Ajax内容获得的XPath。所以web浏览器控件之后完全加载网页。在Document_Complete方法添加一些代码如下:

In C# you can use HTMLAgilityPack to craw data, but if you use webBrowser.DocumentText, you can't load ajax content from webpage to get xpath. So after webBrowser control loaded webpage completely. In Document_Complete method you add some codes below:

HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
this.webBrowser1.Document;
IHTMLDocument2 currentDoc =(IHTMLDocument2)this.webBrowser1.Document.DomDocument;

doc.LoadHtml(currentDoc.activeElement.innerHTML);

这篇关于如何提取网页的动态Ajax内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆