Home > other >  The crawler
The crawler

Time:10-12

Beginners, written with a video, I do not know why is can't run...
Have a brother to solve
Def get_city_aqi (city_pinyin) :
"" "get city AQI "" "
Url='http://pm25.in/' + city_pinyin
R=requests. Get (url, timeout=300)
Soup=BeautifulSoup (r.t ext, 'LXML')
Div_list=soup. Find_all (' div '{' class' : 'span1})

City_aqi=[]

For I in range (8) :
Div_content=div_list
Caption=div_content. Find (' div '{' class' : 'caption'}). The text. The strip ()
(value=https://bbs.csdn.net/topics/div_content.find 'div' {' class ':' value '}). The text. The strip ()
City_aqi. Append (caption, value)
Return city_aqi
Def the main () :
"" "
The main function
"" "
City_pinyin=input (' please enter the city pinyin:)
City_aqi=get_city_aqi (city_pinyin)
Print (city_aqi)
If __name__=="__main__ ':
The main ()
  • Related