2017-07-27 11 views
3

"2005 - 2013"を "2005〜2013の間に飲みます" を掻き取ろうとしていましたが、最初はこのコードが私のために働いていましたが、私の要求はまだPythonリクエストで時々空のリストが返される

import requests, lxml.html, csv 
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) 
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36'} 
page = requests.get('http://www.cellartracker.com/wine.asp? 
iWine=91411',headers=headers) 
print(page.status_code) 
html = lxml.html.fromstring(page.content) 
content_divs = html.xpath('//a[@title="Source: Community"]/text()') 
print(content_divs) 

私はそれがjsのサイトなので、このスクレイピングを行うには、セレンを使用して起動する必要がある場合は必ず、どちらかので、いくつかの基本的なヘルプが有用であろうことを行うにはどのようにわからないそうでない場合は200のステータスコードを持っています! ありがとうございます!セレン

from selenium import webdriver 
url = "https://www.cellartracker.com/wine.asp?iWine=91411" 

driver = webdriver.Chrome(executable_path="chromedriver2.25") 
driver.get(url) 
list = driver.find_elements_by_xpath("//li[contains(.,'review')]") 
for item in list: 
    print(item.text) 
    print("---") 

出力使用

+0

それはjsのサイトの場合は、間違いなくあなたがそれを – gaback

+0

掻き取る 'Selenium'または同様のツールを使用する必要がありますが、私は期待した結果、いないことを確認を得ますそれはなぜ働くことをやめ、同じウェブサイトを何度もパースしようとしていますか?スクレイピングに 'Selenium'を使用するリファレンスが必要な場合、私はこの問題に関する質問に答えました(https://stackoverflow.com/a/45315393/5103802)。 –

答えて

1

Options 
1/4/2014 - REUBENSHAPCOTT WROTE: 
91 Points 
Delicious! Had no idea that Australia made port this good, and affordable. Terrific, smooth fig and plum. Aged and neither sharp nor grapey. If you see it, buy it. 
Do you find this review helpful? Yes - No/Comment 
--- 
Options 
1/20/2013 - LISAADAM WROTE: 
85 Points 
The wine looks Tawny colored. 
Do you find this review helpful? Yes - No/Comment 
--- 
Options 
12/22/2012 - WINEAGGREGATE LIKES THIS WINE: 
90 Points 
Molasses, pepper, butterscotch candy that's been roasted a bit. Very nice. 
Do you find this review helpful? Yes - No/Comment 
--- 
Options 
10/30/2011 - GTI2TON WROTE: 
87 Points 
Sweeter than average tawny and straightforward, but still has nice richness in its raisin and light carmel notes. Good value. 
Do you find this review helpful? Yes - No/Comment 
関連する問題