1

I have to read response from http://www.bk.com/en/us/restaurant-locator/index.html?s=89165 .I have used following code But dose not get all the response. Thanks in advance.

protected void Page_Load(object sender, EventArgs e)
{

    string sUrl = "http://www.bk.com/en/us/restaurant-locator/index.html?s=89165";
    XmlDocument rssDoc = new XmlDocument();
    XmlTextReader rssReader = new XmlTextReader(sUrl.ToString());

    WebRequest wrGETURL;
    wrGETURL = WebRequest.Create(sUrl);

    Stream objStream;
    objStream = wrGETURL.GetResponse().GetResponseStream();
    StreamReader objReader = new StreamReader(objStream, Encoding.UTF8);
    WebResponse wr = wrGETURL.GetResponse();
    Stream receiveStream = wr.GetResponseStream();
    StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8);
    string content = reader.ReadToEnd();
    Response.Write(content);
   }

Is any one help to get all the data appear on web page?

3 Answers 3

1

Unless there is a specific reason for your method, I would use webclient.

Console.Write("\nPlease enter a URI (for example, http://www.contoso.com): ");
string remoteUri = Console.ReadLine();

// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
// Download home page data.
Console.WriteLine("Downloading " + remoteUri);                        
// Download the Web resource and save it into a data buffer.
byte[] myDataBuffer = myWebClient.DownloadData (remoteUri);

// Display the downloaded data.
string download = Encoding.ASCII.GetString(myDataBuffer);
Console.WriteLine(download);

Console.WriteLine("Download successful.");

The above example is directly from the MSDN article.

http://msdn.microsoft.com/en-us/library/xz398a3f.aspx

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

1 Comment

I have to find the address values of that page..i am doing googlescrapper project in that i have to find the addresses on the pages and dup into database. But here i cant get Address values. It shows blank even though address values are present on web page.It did not come in the response. can u please execute this code and u well get same things
1

First, you need to address the way you are downloading the HTML from the website.

  1. Use the XMLDocument.Load method and pass it the URL of the document you want to load.
  2. Use the WebClient.DownloadString method.

Both of which will download the text of the page in about 3 lines, making your above code a lot cleaner.

Secondly, you cannot rely on third party websites to create valid XML/XHTML code, meaning when you try and parse the content using an XMLDocument, it's likely to fail.

Thirdly and probably more importantly, a lot of sites prohibit you from "scraping" content in this method. You might want to double check you are allowed.

Finally.. If you provide us with an idea on what you are looking to find in that page, we might be able to help you further.

6 Comments

I have to find the address values of that page..i am doing googlescrapper project in that i have to find the addresses on the pages and dup into database. But here i cant get Address values. I shows blank even though it is present on web page..Please Help!
What may be useful for you, is that the BK website uses a web service to get the list of locations. http://www.bk.com/en/us/restaurants/40.7143528/-74.0059731/15/5/restaurants.xml - The 40.7143528 and -74.0059731 are the latitude and longitude of the area you want to search, 15 is the mile radius and I assume the 5 is the maximum amount of results.
Yes I want the address values. Consider this URL bk.com/en/us/restaurant-locator/index.html?s=89165 and i want the address values eg. 2180 East Serene Avenue and 7255 South Eastern Avenue..etc
See my previous comment. BK provide an web service that will return all of the information you need, so long as you pass it an latitude/longitude of the area you want. Your mission, should you choose to accept it, is to get the latitude/longitude of 89165, or any other Zip/location that you want to get the list of addresses for.
what i want is the address values present on the page. Is it possible to get that values using response object.
|
0

Try this code here...

         System.Net.HttpWebRequest _HttpWebRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(_URL);

        _HttpWebRequest.AllowWriteStreamBuffering = true;


        // set timeout for 20 seconds (Optional)
        _HttpWebRequest.Timeout = 20000;

        // Request response:
        System.Net.WebResponse _WebResponse = _HttpWebRequest.GetResponse();

        // Open data stream:
        System.IO.Stream _WebStream = _WebResponse.GetResponseStream();

1 Comment

Sorry Dude!Its not working...I did not get all the response that available on web page. can u please check once on your side and let me know the solution. Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.