0

I want to download the final html source from other website(after all javascript code run). For examlple i have a part jquery inside remote html file look like:

$(document).ready(function () {
   $('#dynamic').after('some dynamic content when page load');
});

And this is in my c# code:

var client = new WebClient();            
client.Encoding = System.Text.Encoding.UTF8;            
var content = client.DownloadString("http://myremotedomain.com/");

And also use WebRequest and WebResponse to do the same thing like above. And even use Webbrowser in window form from this link Use webbrowser control in asp.net

But i can not get the final html source , the result just raw html without affected by JavaScript.

Community
  • 1
  • 1
vietvoquoc
  • 813
  • 1
  • 10
  • 23
  • 1
    There is no "after" for javascript code in browser - it runs until you close the page. – zerkms Feb 24 '14 at 04:10
  • Generally you shouldn't do that - it's 2014 and all the sites that want to share their data provide convenient APIs for that. – zerkms Feb 24 '14 at 04:11
  • @zerkms "after" is jquery function! My purpose is download html source from other website using "Webclient","HttpWebRequest,HttpWebResponse" but both of them return the raw html. It mean the html before remote domain populate their html content by jquery plugin or some javascript code. Please let me know if you don't know what i mean! Thanks. – vietvoquoc Feb 24 '14 at 06:17
  • I know what you mean and your understanding about how JS in browsers work is incorrect. – zerkms Feb 24 '14 at 06:24
  • Please give me solutions to solve this problem!? Is there anything in .net can do this. – vietvoquoc Feb 24 '14 at 06:33
  • your question is incorrect, so it cannot be answered. There is no point "after all javascript code run", since it will run while your page is opened. – zerkms Feb 24 '14 at 06:55
  • I mean "after all javascript code run" is in the first time load when i open website. For example the remote website will populate some template in their document when document ready. My idea look like this : http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/HTML/Q_27831163.html – vietvoquoc Feb 24 '14 at 07:06

1 Answers1

1

You will need a headless browser that actually runs the javascript. Check this other post with a list of headless browsers with a C# API. Headless browser for C# (.NET)?

Community
  • 1
  • 1
ryudice
  • 36,476
  • 32
  • 115
  • 163