資源簡介
python爬取網(wǎng)絡(luò)歷史天氣數(shù)據(jù)
代碼片段和文件信息
#?-*-?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
#獲得某一個(gè)月的天氣數(shù)據(jù)
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?獲得某地區(qū)的數(shù)據(jù)
#@par:excelSavePath??數(shù)據(jù)的保存地址
def?getListByAddress(addressUrlexcelSaveP
評(píng)論
共有 條評(píng)論