#!/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'\n空气质量:' + quality[0].text + result.text + weather.text)
    print('*'*20 + ctime() + '*'*20)

def one_thread():
    print('One_thread Start:' + ctime()+'\n')
    getPM25('beijing')
    getPM25('shijiazhuang')
    getPM25('shenzhen')

if __name__ == '__main__':
    one_thread()
View Code

相关文章:

  • 2021-09-16
  • 2021-12-31
  • 2021-11-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-17
  • 2021-08-12
猜你喜欢
  • 2021-09-20
  • 2022-01-21
  • 2021-08-08
  • 2021-08-17
  • 2021-11-17
  • 2022-02-08
  • 2022-12-23
相关资源
相似解决方案