How to recover the page HTML generated with Angularjs via C# ?

Asked

Viewed 493 times

6

How to recover HTML code from a page that uses Angularjs to process some information and generate a graph?
I was able to easily recover the HTML code using Webrequest as demonstrated in the example below, but the content (graphic) generated by Angularjs does not come in the code of the page.

WebRequest request = WebRequest.Create("http://localhost:36789/minhaapp#/index");
WebResponse response = request.GetResponse();
Stream data = response.GetResponseStream();
string html = String.Empty;
using (StreamReader sr = new StreamReader(data))
{
    html = sr.ReadToEnd();
}
  • To put it simply, the whole problem is that in your HTML code everything related to Angularjs is Javascript. When you open the page in a browser the browser itself runs all the Javascript and then generates the content of Angularjs that appears on the screen. When you via an HTTP request receive the HTML content as a string there is nothing to run Javascript and only the code is there anyway.

  • Exactly what @Leonardo said. Your angular chart is rendered after loading into the browser. You may need to use an iframe to solve this problem.

  • You can do this: http://toolsqa.com/selenium-c-sharp/

1 answer

1

If you are allowed to edit the website that generates the graph you must extract the data from the graph via Javascript and send to the server, only the data, via an http request. It is not ideal to send html to the server to extract the data.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.