2017-02-28 28 views
0

獲取URL我的代碼下載圖像與查詢字符串的URL,如果我用PhantomJS任何東西就可以了。但鉻是失敗我的錯誤如下,我能做什麼?webDriver.Chrome()不能與查詢字符串

urlImage = "http://ipcamera-viewer.com/image/?p=199619_20170221_162149_7208.jpg" 
driver = webdriver.Chrome() 
driver.set_window_position(-10000, 0) 
driver.get(urlImage)       <- Error Here 
imgBase64 = driver.get_screenshot_as_base64() 
imgBytes = BytesIO(base64.b64decode(imgBase64)) 
imgBytes.seek(0) 
imgData = PIL.Image.open(imgBytes) 
if rotationAngle != 0: imgData = imgData.rotate(rotationAngle, expand=True) 
imgData.save(pathImage) 

例外:

imgBase64 = driver.get_screenshot_as_base64() 
return self.execute(Command.SCREENSHOT)['value'] 
self.error_handler.check_response(response) 
raise exception_class(message, screen, stacktrace) 
selenium.common.exceptions.WebDriverException: Message: no such session 
(Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Windows NT 10.0.14393 x86_64) 

定期URL規則的代碼,我使用的代碼如下

file = urllib.request.urlopen(urlImage) 
imgData = PIL.Image.open(file) 
+0

我跑你的代碼,它完美的罰款。我使用2.53.5硒和56.0版鉻?你能否提到你的鉻和硒版本。另外,你是否能夠打開任何其他網站? –

+0

我想在Mac和Windows版本在Windows中'3.0.2'和'56.0.2924.87',Mac的硒也高於'3.0',我可以告訴你,今晚如果真正想知道.. – mikezang

+0

你可以嘗試降級Firefox版本。不確定,但如果這是由於兼容性問題,可能會解決。作爲一切工作正常使用Selenium 2 –

回答

0

如何使用requests而不是使用selenium

如果您有具體的網址,獲取資源,你可以只使用requests.get

確保你已經安裝了requests與PIP

下面的代碼:

import requests 
import shutil 

url = 'http://ipcamera-viewer.com/image/?p=199619_20170221_162149_7208.jpg' 
resp = requests.get(url, stream=True) 
with open('199619_20170221_162149_7208.jpg', 'wb') as file: 
    shutil.copyfileobj(resp.raw, file) 
+0

我修改後的代碼如上述,我怎樣才能使用,如果你的代碼圖像旋轉? – mikezang

+0

http://matthiaseisen.com/pp/patterns/p0201/ – Beomi

+0

檢查此鏈接:) – Beomi