', weather,re.S) for x in res[2:]: w = re.findall('>(.*?)<', x,re.S) for y in w[1:]: if len(y.strip())<=0: pass else: print y print '--'*40 这样以来,我们就可以获取到了对应城市的天气情况了!! 完整代码: #coding:UTF-8 import re import requests import sys reload(sys) sys.setdefaultencoding('UTF-8') def ShowWeather(city): res =str(city).split('" title="') print res[1],'(白天-->夜间)' html=requests.get("http://www.tianqihoubao.com/weather/{0}".format(res[0])) weather=re.search('
(.*?)
', html.text,re.S).group(1) res=re.findall('
(.*?)
', weather,re.S) for x in res[2:]: w = re.findall('>(.*?)<', x,re.S) for y in w[1:]: if len(y.strip())<=0: pass else: print y print '--'*40 print '\n','*'*40 def ShowCity(): html=requests.get("http://www.tianqihoubao.com/weather/province.aspx?id=420000") citys= re.findall('