简体   繁体   English

Webbrowser试图解析某些使用ajax加载数据的页面

[英]Webbrowser Trying to parse some page which uses ajax to load data

I am trying to parse some images from this site.. I was using htmlagilitypack for the other pages but this page uses ajax to load images 我正在尝试从该站点解析一些图像。.我在其他页面上使用htmlagilitypack,但是此页面使用ajax加载图像

so this is how the webpage works. 这就是网页的工作方式。

  1. has a div tag including nothing. 没有任何内容的div标签。
  2. right below the div they have a script tag in cdata thing 在div的正下方,他们在cdata中有一个script标签

     <script type="text/javscript> //< ![CDATA[ (function(){ ajax POST request to a 'aaaaaa.js' file with the id parameter and if the request is success, it updates the blank div my changing the innerHTML value. })(); //]]> </script> 

So.. what I tried was... 所以..我尝试的是...

  1. navigate to that page using the webbrowser control. 使用网络浏览器控件导航到该页面。 which loads the image just fine but when I try to get the value of 'DocumentText' it only shows the blank div tag... 加载图像很好,但是当我尝试获取'DocumentText'的值时,它只显示空白的div标签...

  2. try to get straight data from the ajax POST using webrequest and webresponse.. but.. maybe cause its .js file.. it doesnt work.. I only get http errors. 尝试使用webrequest和webresponse从ajax POST获取直接数据.....可能导致其.js文件..它不起作用..我仅收到http错误。

  3. Browse right to the js file with the parameters attached. 浏览带有附加参数的js文件。 gives me an error page 给我一个错误页面

  4. Browse the page Im trying to parse and then navigate to the .js page. 浏览试图解析的页面,然后导航到.js页面。 (I guess the browser caches something when i browse the original page.. but i dont know what it is.) I do get the json response! (我猜浏览器在浏览原始页面时会缓存某些内容。但是我不知道它是什么。)我确实得到了json响应! i can use this data.. but since the webbrowser control is using IE. 我可以使用此数据..但是由于webbrowser控件正在使用IE。 It just asks me if i want to download the responsed js file. 它只是问我是否要下载响应的js文件。

So theres the method of using the DOM I mentioned in my comment. 因此,有一种使用我在评论中提到的DOM的方法。

Another method could be to use FiddlerCore ( http://www.fiddler2.com/fiddler/Core/ ) 另一种方法是使用FiddlerCore( http://www.fiddler2.com/fiddler/Core/

Or make the ajax call yourself. 或者让ajax自己打电话。 You will have to make sure you respect cookies, redirects, and all the headers. 您必须确保遵守Cookie,重定向和所有标题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM