python爬天气预报

Posted 、工藤新一

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python爬天气预报相关的知识,希望对你有一定的参考价值。

python爬天气预报

from urllib.request import urlopen#获取页面

from bs4 import BeautifulSoup#从网页抓取数据

html=urlopen(r"http://www.weather.com.cn/weather/101090101.shtml").read().decode('utf-8')对中文解码

#print(html)

soup=BeautifulSoup(html,features="lxml")

all_ul=soup.find_all("ul",attrs={"class":"t clearfix"})

all_li=all_ul[0].find_all('li')

for i in all_li:

h1=i.find("h1").get_text()

p1=i.find("p",attrs={"class":"wea"}).get_text()

p2=i.find("p",attrs={"class":"tem"}).get_text()

print("==============")

print(h1)

print(p1)

print(p2)


--------------------------------------------------

附:Python制作二维码简易步骤

Python制作二维码简易步骤

附:Python爬取整本小说

Python爬取整本小说

附:Python爬天气预报

Python爬天气预报

附:Python爬取百度图片

Python爬取百度图片

附:python图片转字符画

python图片转字符画

以上是关于python爬天气预报的主要内容,如果未能解决你的问题,请参考以下文章