資源簡介
python爬取網絡歷史天氣數據
代碼片段和文件信息
#?-*-?coding:?utf-8?-*-
“““
Created?on?Fri?May?19?17:10:31?2017
@author:?Starry_JM
“““
from?bs4?import?BeautifulSoup
import?requests
import?xlwt
import?os
#獲得某一個月的天氣數據
def?getListByUrl(url):
????res?=?requests.get(url)
????soup?=?BeautifulSoup(res.text“html.parser“)
????weathers?=?soup.select(“#tool_site“)
????title?=?weathers[1].select(“h3“)[0].text
????weatherInfors?=?weathers[1].select(“ul“)
????weatherList?=?list()
????for?weatherInfor?in?weatherInfors:
????????singleWeather?=?list()
????????for?li?in?weatherInfor.select(‘li‘):
????????????singleWeather.append(li.text)
????????weatherList.append(singleWeather)
????print(title)
????return?weatherListtitle
#@par:addressUrl?獲得某地區的數據
#@par:excelSavePath??數據的保存地址
def?getListByAddress(addressUrlexcelSaveP
- 上一篇:crc32碰撞python
- 下一篇:Python采集百度地圖數據.zip
評論
共有 條評論