Traditional Culture Encyclopedia - Weather inquiry - How to get the weather in webBrowser in c#

How to get the weather in webBrowser in c#

This is definitely the case. .

Because the Webbrower control is a mini browser. When you enter a URL, it will definitely bring back the content of the entire web page. How can it only return weather information to you?

If you want to display the weather, you can follow my method below:

Note that for the /inc/ss1.htm address, you can choose the city you want! ! ///?

?

///?Get weather data?

///?

?

///? Array (0, weather; 1, temperature; 2, wind; 3, ultraviolet light; 4, air)?

public?static?string[]?GetWeather()

{

Regex?regex;

string[]?weather?=?new?string[5];

string?content? =?"";

Match?mcTmp;

Match?mcCity;

int?k?=?1;

HttpWebResponse ?theResponse;

WebRequest?theRequest;

//ss1.htm?Note: ss1-ss303 represents different cities and is discontinuous. ss1 represents Hong Kong

< p>theRequest?=?WebRequest.Create("/inc/ss1.htm");

try

{

theResponse?=?(HttpWebResponse) theRequest.GetResponse();

using?(System.IO.Stream?sm?=?theResponse.GetResponseStream())

{

System.IO .StreamReader?read?=?new?System.IO.StreamReader(sm,?Encoding.Default);

content?=?read.ReadToEnd();

}

}

p>

}

catch?(Exception)

{

content?=?"";

}

string?parttenTmp?=?"(?[^<]+)";

k?=?1;

regex?=?new?Regex(parttenTmp,? RegexOptions.Compiled?|?RegexOptions.IgnoreCase);

for?(mcTmp?=?regex.Match(content),?k?=?1;?mcTmp.Success;?mcTmp?=?mcTmp .NextMatch(),?k++)

{

weather[0]?=?mcTmp.Groups["item1"].Value;

}< /p>

parttenTmp?=?"height=\"23\"?align=\"center\">(?[^/]+)";

k?=?1;

regex?=?new?Regex(parttenTmp,?RegexOptions.Compiled?|?RegexOptions.IgnoreCase);

for?(mcTmp?=? regex.Match(content),?k?=?1;?mcTmp.Success;?mcTmp?=?mcTmp.NextMatch(),?k++)

{

weather[ k]?=?mcTmp.Groups["item1"].Value;

}

return?weather;

}

Result: