我很難找出一個正確的路徑與我的網頁抓取代碼。網絡抓取,獲取空列表
我想從http://financials.morningstar.com/company-profile/c.action?t=AAPL刮取不同的信息。 我已經嘗試了幾條路徑,有些似乎有效,有些則沒有。 我感興趣的CIK下的操作細節
page = requests.get('http://financials.morningstar.com/company-profile/c.action?t=AAPL')
tree=html.fromstring(page.text)
#desc = tree.xpath('//div[@class="r_title"]/span[@class="gry"]/text()') #works
#desc = tree.xpath('//div[@class="wrapper"]//div[@class="headerwrap"]//div[@class="h_Logo"]//div[@class="h_Logo_row1"]//div[@class="greeter"]/text()') #works
#desc = tree.xpath('//div[@id="OAS_TopLeft"]//script[@type="text/javascript"]/text()') #works
desc = tree.xpath('//div[@class="col2"]//div[@id="OperationDetails"]//table[@class="r_table1 r_txt2"]//tbody//tr//th[@class="row_lbl"]/text()')
我想不通的最後一條路徑。這似乎是我正確地遵循路徑,但我得到空列表。
最後一個元素th,它是html中的表頭,因此您可能需要將其更改爲用於表數據的td。 – postelrich
http://stackoverflow.com/questions/24163745/beginner-to-scraping-keep-on-getting-empty-lists這可能是一個類似的問題,你的看看 –
http://stackoverflow.com/questions/ 33110734/xpath-not-working-for-screen-scraping/33111061?noredirect = 1#comment54037557_33111061這裏是一個像這樣的html錯誤導致一個空分析 – rebeling