0

Is it possible? I mean, I have loaded html page (with HtmlAgilityPack for example) and javascript file. I need to apply javascript method from this file (or whole javascript file) to my loaded html page and do this from C# code. Then save result html to filesystem. Can I do that?

nemocean
  • 159
  • 2
  • 14
  • Why do you want to use javascript instead of just straight C#? – Abe Miessler May 04 '11 at 20:02
  • @Abe - I am assuming he is scraping the HTML but need the Javascript to have executed on the loaded page in order to get the end result as it would have appeared to a normal browser. – Oded May 04 '11 at 20:05
  • @Abe - because I need to fire javascript events on this html document. For example one method will check checkbox and all other checkboxes will be checked too ('change' event will be fired). If I'll try to change HTML document with C#, all these events will not work – nemocean May 04 '11 at 20:39

2 Answers2

1

You will need to use a headless browser to apply the javascript to the page first.

See this SO question about headless browsers for .NET - there should be something suitable.

Community
  • 1
  • 1
Oded
  • 489,969
  • 99
  • 883
  • 1,009
0

If this is a winforms app, you might be able to use the web browser control to load the page (which should then fire the javascript) and then try to scrape the resulting HTML from the page.

Charles Boyung
  • 2,464
  • 1
  • 21
  • 31