gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 13:42:19 26 4
gpt4 key购买 nike

我想从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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com