Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get data from web page?

I want to get the data from this page and insert it to my mssql database. How can I read this data with asp.net c#? SehisID is a value from 1 to 81.

EDIT: My code is below.

for (int i = 1; i <= 81; i++)
{
    HttpWebRequest rqst = (HttpWebRequest)WebRequest.Create("http://www.milliyet.com.tr/Secim2009/api/belediyelist.ashx?sehirid=" + i);
    rqst.Method = "POST";
    rqst.ContentType = "text/xml";
    rqst.ContentLength = 0;
    rqst.Timeout = 3000;

    HttpWebResponse rspns = (HttpWebResponse)rqst.GetResponse();
    form1.InnerHtml += rspns.ToString() + "<br>";
}
like image 694
HasanG Avatar asked Dec 23 '22 00:12

HasanG


2 Answers

WebClient is an easy way to get a string from a web page:

WebClient client = new WebClient();
String downloadedString = client.DownloadString("http://www.milliyet.com.tr/Secim2009/api/belediyelist.ashx?sehirid=81");
like image 194
PhilPursglove Avatar answered Jan 11 '23 08:01

PhilPursglove


And next code works well too:

        for (int i = 1; i <= 81; i++)
        {
            var rqst = (HttpWebRequest)WebRequest.Create("http://www.milliyet.com.tr/Secim2009/api/belediyelist.ashx?sehirid=" + i);
            rqst.Method = "POST";
            rqst.ContentType = "text/xml";
            rqst.ContentLength = 0;
            rqst.Timeout = 3000;

            var rspns = (HttpWebResponse)rqst.GetResponse();
            var reader = new StreamReader(rspns.GetResponseStream());
            form1.InnerHtml += reader.ReadToEnd() + "<br>";
        }
like image 40
SKINDER Avatar answered Jan 11 '23 09:01

SKINDER