1
我對python非常陌生(事實上,這是我的第一個Python項目),我在編寫這個web刮板時遇到了一些麻煩。我用tutorial來解決這個問題,但代碼沒有產生任何結果。我真的很感謝一些幫助。刮板不會產生任何結果
from lxml import html
import requests
page = requests.get('http://openbook.sfgov.org/openbooks/cgi-bin/cognosisapi.dll?b_action=cognosViewer&ui.action=run&ui.object=/content/folder%5B%40name%3D%27Reports%27%5D/report%5B%40name%3D%27Budget%27%5D&ui.name=20Budget&run.outputFormat=&run.prompt=false')
tree = html.fromstring(page.content)
#This will find the table headers:
categories = tree.xpath('//*[@id="rt_NS_"]/tbody/tr[2]/td/table/tbody/tr[4]/td/table/tbody/tr[2]/td/div/div/table/tbody/tr/td[2]/table/tbody/tr[2]/td[1]')
# This will find the budgets
category_budget = tree.xpath('//*[@id="rt_NS_"]/tbody/tr[2]/td/table/tbody/tr[4]/td/table/tbody/tr[2]/td/div/div/table/tbody/tr/td[2]/table/tbody/tr[2]/td[2]/span[1]')
print 'Cateogries: ', categories
print 'Budget: ', category_budget
這是不幸的,但謝謝你看Samuel!看起來這是[相關文章](http://stackoverflow.com/questions/19738920/python-selenium-scraping-webpage-javascript-table)。這應該有助於我走向正確的方向。你搖滾! – tonestrike