webDriver.Chrome()无法通过查询字符串获取url

时间:2017-02-28 15:09:18

标签: python image selenium get selenium-chromedriver

我有代码用查询字符串url下载图片,代码如下,我该怎么办才能解决这个问题?

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)

例外:

self.run()
self._target(*self._args, **self._kwargs)
driver.get(urlImage)
self.execute(Command.GET, {'url': url})
response = self.command_executor.execute(driver_command, params)
return self._request(command_info[0], url, body=data)
resp = self._conn.getresponse()
raise ResponseNotReady(self.__state)
http.client.ResponseNotReady: Idle

1 个答案:

答案 0 :(得分:0)

如何使用requests而不是selenium

如果您有获取资源的特定网址,则可以使用requests.get

  

确保您已使用pip

安装了requests

这里是代码:

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)