2017-12-19 4 views
0

?右クリックで画像をダウンロードする方法

from selenium import webdriver 
 
from selenium.webdriver import ActionChains 
 

 
def isExistsByXpath(xpath): 
 
    try: 
 
     element = driver.find_element_by_xpath(xpath) 
 
     return True 
 
    except Exception as e: 
 
     return False 
 

 
driver = webdriver.Firefox() 
 
driver.implicitly_wait(30) 
 
driver.get("http://callback.ganji.com/firewall/valid/920573663.do?namespace=ganji_hy_detail_pc&url=http%3A%2F%2Fanshan.ganji.com%2Fzhiyepeixun%2F944875012x.htm") 
 
while not isExistsByXpath('//img[@class="dvc-captcha__bgImg"]'): 
 
    driver.find_element_by_xpath('//input[@id="btnSubmit"]').click() 
 
element = driver.find_element_by_xpath('//img[@class="dvc-captcha__bgImg"]') 
 
action = ActionChains(driver) 
 
action.move_to_element(element).context_click(element).perform()

?私は 'send_keys'を使用しようとしますが、動作しません。

ヘルプしてください

  • のpython 3.6
  • のUbuntu 17.04
+0

が重複する可能性のようなものを試してみてください?](https://stackoverflow.com/questions/6813704/how-to-download-an-image-using-selenium-any-version) –

+0

私の場合、画像のURLには一度しかアクセスできません。 したがって、要求の再送信は機能しません。 – user8942934

+0

[Python:ウェブページでセレンをダウンロードできません](https://stackoverflow.com/questions/44072022/python-unable-to-download-with-selenium-in-webpage)の可能な複製 – DebanjanB

答えて

0

[セレン(任意のバージョン)を使用してイメージをダウンロードする方法のこと

import urllib 
from selenium import webdriver 

driver = webdriver.Chrome() 
driver.get('YOUR_URL') 

# get the image source 
image_path = driver.find_element_by_xpath('IMAGE_XPATH') 
src = img.get_attribute('src') 

# download the image 
urllib.urlretrieve(src, "captcha.png") 

driver.close() 
関連する問題