#!/usr/bin/env python # -*- coding:utf-8 -*- #@Time : 2020/4/22 16:14 #@Author: ltl #@File : PM2.5Download.py import urllib.request import threading from time import ctime from bs4 import BeautifulSoup def getPM25(cityname): site = 'http://www.pm25.com/' + cityname + '.html' html = urllib.request.urlopen(site) soup = BeautifulSoup(html,'html.parser') city = soup.find(class_ = 'bi_loaction_city') aqi = soup.find('a',{"class","bi_aqiarea_num"}) quality = soup.select(".bi_aqiarea_right span") result = soup.find("div", class_ = 'bi_aqiarea_bottom') weather = soup.find("p",{"class","bi_info_weather"}) print(city.text + u'AQI指数:' + aqi.text + u' 空气质量:' + quality[0].text + result.text + weather.text) print('*'*20 + ctime() + '*'*20) def one_thread(): print('One_thread Start:' + ctime()+' ') getPM25('beijing') getPM25('shijiazhuang') getPM25('shenzhen') if __name__ == '__main__': one_thread()
结果: