附件
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在数据获取和简单图像处理方面的能力。
696





