c# - 如何从网页中获取数据?

标签 c# asp.net httpwebrequest xmlhttprequest

我想从this中获取数据页面并将其插入到我的 mssql 数据库中。如何使用 asp.net c# 读取这些数据? SehisID 是一个从 1 到 81 的值。

编辑: 我的代码如下。

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>";
}

最佳答案

WebClient 是一种从网页获取字符串的简单方法:

WebClient client = new WebClient();
String downloadedString = client.DownloadString("http://www.milliyet.com.tr/Secim2009/api/belediyelist.ashx?sehirid=81");

关于c# - 如何从网页中获取数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3354665/

相关文章:

c# - HttpWebRequest: The request was aborted: 请求被取消

c# - HttpWebRequest 只是卡在一台电脑上

c# - knockout : Posting complex type to MVC controller query

c# - RabbitMQ 基本恢复不起作用

c# - 开始学习 ASP.NET 的好地方

c# - 如何从 ASP.NET 应用程序连接到服务器端 USB (HID) 设备?

.net - 在 ASP.NET 动态数据/LINQ to SQL 中启用编辑主键字段

c# - ModelStateDictionairy 格式错误的 json Web api

c# - 用于 Linux 的单声道 VLC API

http - 在 Firefox 中使用篡改数据篡改 GET 请求参数?