In learning Python, see a Python script for getting the weather, http://xianglong.me/article/get-city-weather-using-python-script/, this is too much trouble, Wrote a simple script with BeautifulSoup,
#-*-coding:cp936-*-import sysimport httplibimport reimport requestsimport jsonimport urllibfrom BS4 Import BeautifulSo Updef Wea (): r = requests.get (' http://weather.sina.com.cn ') print r.status_code f = open (' 1.html ', ' w+ ') f.write (r.content) f.close () soup = beautifulsoup (open (' 1.html '), "lxml") #print Soup.title.encode (' GB18030 ') data = {} for link in soup.find_all (' P ', Attrs ={"class": "Wt_fc_c0_i_day"}): temp = link.find_next_sibling (' P ', Attrs ={"class": "Wt_fc_c0_i_temp"}) WEA = Link.find_next ("img") Data[link.text] = temp.text + wea[' title '] for text in data: print text,data[text]if __name__ = = ' __main_ _ ': Wea ()
Python gets a week of weather content