6

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

3
  • 1
    Can you elaborate on why using the WebBrowser class is not an option? 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. Commented Nov 16, 2012 at 19:37
  • WebBrowser is slow and sometimes buggy, speed matters to me. Commented Nov 16, 2012 at 19:49

3 Answers 3

3

You 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.

Sign up to request clarification or add additional context in comments.

1 Comment

I think the quick and easy way to do this is the WebBrowser control, the best one for him is using that .NET WebKit wrapper.
1

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.org/

1 Comment

Interesting project, but it appears to be more freestanding and not for use in C#.
0

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.)

2 Comments

and what did you use to execute the javascript without the ajax calls?
Sync Javascript executes anyway in any web request. It's only with async code(ajax calls, callbacks) that it fails. To answer the question: I used the WebRequest class in ASP.NET.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.