0

Here is some code,to request html-code from url.

var currentUrl = "https://www.google.com";
HttpClient client = new HttpClient();
System.Diagnostics.Process.Start(currentUrl); //here i open a browser with same URL, 
var response = await client.GetAsync(currentUrl);
string sourse = null;


if (response != null && response.StatusCode == HttpStatusCode.OK)
{
     sourse =await response.Content.ReadAsStringAsync(); // here i get the html-code
}

SO, the questions is: why html code that i get from program,and html code from real page in browser i have opened few secods before are different? It doesn't make sence.

Also, here is some proofs. First image - number of character in browser-html code enter image description here

... and in program-html code enter image description here

I gave the simplest evidence, to make the question more easier. But if I dig deeper, the html code comes from nowhere. When I parse a specific page, and it should be 39 products, the program returns the html code, which only 6 products (which, incidentally, are not included in the 39 those that are actually on the page in the browser). So I asked the question so simply. Really,i make a new project a minute ago with this code, and it work incorrect as I wrote above. to get the code that the program returns, I can look it up in the sourse variable or leave it in a file, and then compare. Like:

        FileStream fs = new FileStream("report.txt", FileMode.OpenOrCreate);
        StreamWriter SW = new StreamWriter(fs);
        SW.WriteLine(sourse);
Mister Crabs
  • 41
  • 1
  • 5
  • What makes you think it's invalid? How can you tell? And have you considered that your browser may be providing a lot more HTTP headers when it makes that GET request to google than your HttpClient is? – mason Mar 26 '19 at 19:27
  • HttpClient is not browser. Browser will download the page, render it and run scripts in it, HttpClient will not do it. – CSakura Mar 26 '19 at 22:29
  • Hmmm, ok. But how can i load the page like in the browser,and get correct html code? – Mister Crabs Mar 26 '19 at 23:23
  • @MisterCrabs You are looking at browser controls, like https://cefsharp.github.io/, or .Net Framework's WebBrowser. No matter what you choose, you should check your goal. Why are you getting HTML code? – CSakura Mar 27 '19 at 19:59

0 Answers0