页面源码分析
import urllib
.request
from bs4
import BeautifulSoup
url
= "http://www.weather.com.cn/weather/101250101.shtml"
content
= urllib
.request
.urlopen
(url
).read
()
soup
= BeautifulSoup
(content
, "html.parser")
content
= ""
name
= soup
.find_all
(attrs
={"class": "sky skyid lv1 on"})
for u
in name
:
wea
= u
.find
(attrs
={"class": "wea"}).get_text
()
tem
= u
.find
(attrs
={"class": "tem"}).get_text
()
win
= u
.find
(attrs
={"class": "win"}).get_text
()
content
= "天气:" + wea
+ " 温度:" + tem
+ " 风速:" + win
content
= content
.replace
("\n", "")
print(content
)
转载请注明原文地址: https://lol.8miu.com/read-30205.html