【发布时间】:2019-11-27 06:42:04
【问题描述】:
我是python新手
我想从网站“http://www.estesparkweather.net/archive_reports.php?date=200901”抓取天气数据 我必须从 2009-01-01 到 2018-10-28 每天抓取所有可用的天气数据属性 我必须将抓取的数据表示为 pandas 数据框对象。
下面应该是 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
抓取后,我需要将数据框保存为名称为“dataframe.pk”的pickle文件
下面是我最初尝试使用 Beautifulsoup 阅读页面的代码,但是每月有多个页面,我不确定如何循环 2009 年 1 月到 2018 年 10 月的网址并将该内容放入汤中,有人可以帮忙吗:
***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])***
【问题讨论】:
-
不同页面是如何实现的?您是否查看过该页面的来源?
标签: python pandas web-scraping beautifulsoup