2017-02-28 61 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