如何使用Selenium for Python下载图像?;
我用Selenium打开页面-如何使用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
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)