Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从多个页面抓取天气数据_Python_Pandas_Web Scraping_Beautifulsoup - Fatal编程技术网

Python 从多个页面抓取天气数据

Python 从多个页面抓取天气数据,python,pandas,web-scraping,beautifulsoup,Python,Pandas,Web Scraping,Beautifulsoup,我是python新手 我想从网站“”中获取天气数据 从2009年1月1日到2018年10月28日,我每天都要搜集所有可用的天气数据属性 我必须将刮取的数据表示为dataframe对象 下面应该是数据帧特定的详细信息 Expected column names (order dose not matter): ['Average temperature (°F)', 'Average humidity (%)', 'Average dewpoint (°F)', 'Average barom

我是python新手

我想从网站“”中获取天气数据 从2009年1月1日到2018年10月28日,我每天都要搜集所有可用的天气数据属性 我必须将刮取的数据表示为dataframe对象

下面应该是数据帧特定的详细信息

Expected column names (order dose not matter):

 ['Average temperature (°F)', 'Average humidity (%)',
 'Average dewpoint (°F)', 'Average barometer (in)',
 'Average windspeed (mph)', 'Average gustspeed (mph)',
 'Average direction (°deg)', 'Rainfall for month (in)',
 'Rainfall for year (in)', 'Maximum rain per minute',
 'Maximum temperature (°F)', 'Minimum temperature (°F)',
 'Maximum humidity (%)', 'Minimum humidity (%)', 'Maximum pressure',
 'Minimum pressure', 'Maximum windspeed (mph)',
 'Maximum gust speed (mph)', 'Maximum heat index (°F)']

Each record in the dataframe corresponds to weather details of a given day
The index column is date-time format (yyyy-mm-dd)
I need to perform necessary data cleaning and type cast each attributes to relevent data type
刮片后,我需要将数据帧保存为pickle文件,名称为“dataframe.pk”

下面是我最初尝试使用Beautifulsoup阅读页面的代码,但每个月都有多个页面,我不确定如何循环2009年1月至2018年10月的URL,并将这些内容放入soup,有人能帮我吗:

***import bs4
from bs4 import BeautifulSoup
import csv
import requests
import time
import pandas as pd
import urllib
import re
import pickle
import numpy as np
url = "http://www.estesparkweather.net/archive_reports.php?date=200901"
page = requests.get(url)
soup=BeautifulSoup(page.content,"html.parser")
type(soup)
bs4.BeautifulSoup
# Get the title
title = soup.title
print(title)
# Print out the text
text = soup.get_text()
print(soup.text)

# Print the first 10 rows for sanity check
rows = soup.find_all('tr')
print(rows[:10])***

要阅读2009-01-01至2018-10-28期间的信息,您必须了解URL模式

http://www.estesparkweather.net/archive_reports.php?date=YYYYMM
例如:

http://www.estesparkweather.net/archive_reports.php?date=201008
因此,您需要创建一个嵌套循环,用于读取每个年/月组合的数据

比如:

URL_TEMPLATE = 'http://www.estesparkweather.net/archive_reports.php?date={}{}'
for year in range(2009,2018):
  for month in range(1,12):
     url = URL_TEMPLATE.format(year,month) 
     # TODO implement the actual scraping of a single page
     # Note that you will need to pad single digit month with zeros

不同的页面是如何实现的?你看过这页的来源了吗?