-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.

1
  • Take a look at How to Ask to read how to structure your question and help us to answer you ;) Commented Oct 23, 2014 at 13:21

1 Answer 1

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#

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for your quick response. But I'm getting the same result. Data = " "
request and response are passed OK? Do you have any errors when debugging?
Yes, they passed OK. And no errors. StatusCode = OK, StatusDescription = OK, ContentLength = 4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.