Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Selenium for Python下载图像?;_Python_Python 2.7_Google Chrome_Selenium Chromedriver_Macos Mojave - Fatal编程技术网

如何使用Selenium for Python下载图像?;

如何使用Selenium for Python下载图像?;,python,python-2.7,google-chrome,selenium-chromedriver,macos-mojave,Python,Python 2.7,Google Chrome,Selenium Chromedriver,Macos Mojave,我用Selenium打开页面- driver = webdriver.Chrome() # login steps are here driver.get('https://www.example.com/?file=%d' % (FILE_ID) ) 该页面包含源等于的img元素https://www.example.com/?file=%d“%(文件ID)value 现在我想把它另存为GIF 我尝试了以下方法- save_me = ActionChains(driver).key_down

我用Selenium打开页面-

driver = webdriver.Chrome()
# login steps are here
driver.get('https://www.example.com/?file=%d' % (FILE_ID) )
该页面包含源等于
img
元素https://www.example.com/?file=%d“%(文件ID)
value

现在我想把它另存为GIF

我尝试了以下方法-

save_me = ActionChains(driver).key_down(Keys.COMMAND).key_down('s').key_up(Keys.COMMAND).key_up('s')
save_me.build().perform()
--什么也没发生(OSX 10.14.15,最新的Chrome)

--它会打开关联菜单,但之后什么也不会发生

content = driver.page_source
with open('1.gif', 'w') as f:
     f.write(content)
--它创建页面的文件HTML内容

我也不能仅仅获得源代码值并下载带有
请求
urllib
等的页面-它需要模拟所有登录步骤等

我还可以尝试保存图片吗

content = driver.page_source
with open('1.gif', 'w') as f:
     f.write(content)