-1

I have read most of the answers with my question. But I get nothing from this url. Well, actually I'm getting " "

This is the url:

http://www.casadellibro.com/busqueda-generica?busqueda=9783126759120&nivel=5&auto=0&maxresultados=-1

My code:

System.Net.WebRequest req = System.Net.WebRequest.Create(url);
System.Net.WebResponse resp = req.GetResponse();
System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
string response = sr.ReadToEnd();

Any idea?

Thank you in advance.

George
  • 36,413
  • 9
  • 66
  • 103
Noarge
  • 1

1 Answers1

1

Getting HTML code from a website. You can use code like this.

string urlAddress = "http://google.com";

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlAddress);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
  Stream receiveStream = response.GetResponseStream();
  StreamReader readStream = null;
  if (response.CharacterSet == null)
    readStream = new StreamReader(receiveStream);
  else
    readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));
  string data = readStream.ReadToEnd();
  response.Close();
  readStream.Close();
}

This will give you the returned HTML code from the website. But find text via LINQ is not that easy. Perhaps it is better to use regular expression but that does not play well with HTML code

Read all reactions here: Get HTML code from website in C#

Community
  • 1
  • 1
Matheno
  • 4,112
  • 6
  • 36
  • 53