2017-05-07 4 views
3

https://www.google.com/flights/exploreから一部の運賃情報を抽出しようとしましたが、取得したスクリーンショットは空白です。誰が問題が何かを見ることができますか?セレンを使用して航空便の価格コンテンツを抽出する際に問題が発生しました

from selenium import webdriver 
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 
from bs4 import BeautifulSoup 

url = "https://www.google.com/flights/explore/#explore;f=JFK,EWR,LGA;t=r-Mexico-0x84043a3b88685353%253A0xed64b4be6b099811;li=3;lx=12;d=2017-05-13" 
driver = webdriver.PhantomJS() 
dcap = dict(DesiredCapabilities.PHANTOMJS) 
dcap["phantomjs.page.settings.userAgent"] = (my_agent) 
driver = webdriver.PhantomJS(desired_capabilities = dcap,service_args=['--ignore-ssl-errors=true']) 
driver.implicitly_wait(20) 
driver.get(url) 

driver.save_screenshot(r'flight_explorer.png') 
+1

を試してみてください。 – kushal

+0

こんにちはkushal、私はhttp://selenium-python.readthedocs.io/waits.html#explicit-waitsから示された明示的な待機を試みましたが、それでも動作しません。私が正しいことをしているかどうかはわかりません。 –

答えて

3

スナップショットを取る前に、いくつかの明示的な待ち時間を追加し、この

from selenium import webdriver 
from selenium.webdriver.common.by import By 
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC 
url = "https://www.google.com/flights/explore/#explore;f=JFK,EWR,LGA;t=r-Mexico-0x84043a3b88685353%253A0xed64b4be6b099811;li=3;lx=12;d=2017-05-13" 
driver = webdriver.PhantomJS() 
driver.get(url) 
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "//div[@elt='results']//img[@class='LJTSM3-v-a']"))) 
print driver.current_url 
driver.save_screenshot(r'flight_explorer.png') 

result i got

+0

それは働いた!ありがとうございました。 –

関連する問題