你欠我一杯啤酒! :)
/tmp ~ python test2.py
/tmp ~ cat out.csv
County,Sequence,Sidetrack,Year,Oil Production(barrels),Oil Sales(barrels),Gas Production(MCF),Gas Sales(MCF),Water Production(barrels),Location
001,05242,00,2014,116,66,,,"2,958",SWSE 22 2S 57W
001,05289,00,2014,268,152,,,"4,080",NWNE 22 2S 57W
運行pip install beautifulsoup4 requests
,你是好去:)價值maxrec
設立項目的所需量。
import requests
from bs4 import BeautifulSoup
import csv
import sys
postdata = {
'grouping_type': "wells",
'FromYear': '2012',
'ToYear': '2014',
'maxrec': '5000'
}
r = requests.post('http://cogcc.state.co.us/cogis/ProductionSearch2.asp',
data=postdata, timeout=3600.0)
if r.status_code != 200:
print("Got status code {}, cannot proceed".format(r.status_code))
sys.exit(1)
soup = BeautifulSoup(r.text)
trlist = soup.findAll('table')[1].findAll("tr")
header = trlist[1]
data = trlist[2:]
with open('out.csv', 'wb') as csvfile:
csvwriter = csv.writer(csvfile)
csvwriter.writerow([row.get_text() for row in header.find_all("th")])
for entry in data:
csvwriter.writerow([' '.join(item.get_text().split())
for item in entry.findAll("td")])
好像如果設置maxrec > 5125
約,你會得到一個服務器錯誤:/
所有最優秀的!
好東西@brunsgaard!然而需要一些小的調整[row.get_text()應該只是row.text]。一杯啤酒肯定是在卡 – raul
@ user3602491 :) – brunsgaard
其實我在代碼上做了一點點工作,其他晚上.. https://gist.github.com/brunsgaard/c3d12be20fa58c4cbe5c 與我發現85183油井。 – brunsgaard