Web サイトからデータを取得したいのですが、コードで URL を取得できません。状態が常に false の場合、「weather1」というテキストボックスには常に「ece」が表示されるためです。textbox の値を「ece」ではなく e.Result にすると、「 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);
}