我想从网站获取一些数据,但我的代码无法获取网址。因为如果状态总是假的,我的名为“weather1”的文本框总是显示“ece”。 当我将textbox的值设为 e.Result 而不是“ece”时,它会显示“ DownloadStringCompletedEventArgs ”。
并且没有错误或警告。
我该怎么办?代码有什么问题?
public void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (!e.Cancelled && e.Error == null)
{
string res = Convert.ToString(e.Result);
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(res);
var table = doc.DocumentNode.SelectSingleNode("//table[@class='tbl_sond']");
var degree = table.SelectSingleNode("//td[@class='renkMax']");
var date = table.SelectSingleNode("//td[@class='sond_zaman']");
}
else weather1.Text = "ece";
}
public void getWeatherInfo() {
string url = "http://www.mgm.gov.tr/tahmin/il-ve-ilceler.aspx?m=ISTANBUL";
WebClient webclient = new WebClient();
webclient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
Uri uri = new Uri(url);
webclient.DownloadStringAsync(uri);
}