admin管理员组文章数量:1332395
is there a way to fetch a webpage with HTTPWebRequest and then execute all the javascriptcode that was on the page along with ajax calls and save the result to a string?
I want to parse a website where some images are generated via js code and the images aren't on the webpage before the js script has run.
Now I searched the web for a solution to this but all I found were answers like this isn't possible, use the webbrowser instead which is not an option for me.
Greetings
is there a way to fetch a webpage with HTTPWebRequest and then execute all the javascriptcode that was on the page along with ajax calls and save the result to a string?
I want to parse a website where some images are generated via js code and the images aren't on the webpage before the js script has run.
Now I searched the web for a solution to this but all I found were answers like this isn't possible, use the webbrowser instead which is not an option for me.
Greetings
Share Improve this question asked Nov 16, 2012 at 19:34 maddo7maddo7 4,9837 gold badges32 silver badges54 bronze badges 3- 1 Can you elaborate on why using the WebBrowser class is not an option? – alexn Commented Nov 16, 2012 at 19:35
-
notions.okuda.ca/2009/06/11/… elaboration on what alexn is suggesting. I can't tell from your Q if you can't use the
WebBrowser
object if you can't use a web browser. – Eli Gassert Commented Nov 16, 2012 at 19:37 - WebBrowser is slow and sometimes buggy, speed matters to me. – maddo7 Commented Nov 16, 2012 at 19:49
3 Answers
Reset to default 3You could do this with the C++ http system which gives you a lot of control over the pieces of data that are receievd, but I guess that's not really an answer so...
Why not try putting webkit into your app, and running off the events from it. It has several events that can notify you when downloads are started and finished.
I did a little research just because I thought it was interesting. I found something called Phantom.js which looks like it does what you need. Check it out: http://phantomjs/
This indeed isn't possible, as I found out while trying to meet a much-required demand. The Javascript will execute, but the Ajax calls won't be made.
The solution I settled for was to get all the data the Ajax calls would have synchronously, through the code-behind file(C# code), and to assign code-behind variables to Javascript variables, using script tags, and let Javascript do its work(building dynamic elements etc.)
本文标签: C Pull a webpage with HTTPWebRequest and execute the javascript from the siteStack Overflow
版权声明:本文标题:C# Pull a webpage with HTTPWebRequest and execute the javascript from the site - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742281994a2446262.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论