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?
///??
///?
public?static?string[]?GetWeather() p>
{
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?=?"";
} p>
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:
- Previous article:Is Huawei p60art worth buying?
- Next article:The omen of dreaming of Dongguan
- Related articles
- Which season is the rainy season in southern Jiangxi?
- What is the indoor soilless culture technology of watercress?
- The harbinger of Jinan airport wireless network dream
- The vegetable garden is very healing.
- Record a trip of Yin Ping who was "soaked to the skin"
- What clothes should I wear in the weather of 5 degrees?
- The best season to travel to Myanmar
- How to restore the time and weather on OPPO desktop if I accidentally deleted it?
- Oil in summer, rough to the touch, stinging and dry in winter? What kind of skin is this? Also, I just took a shower for 20 minutes this season, and I feel it.
- Good morning with pictures: the best thing is actually falling in love with this world.