如何使用Selenium WebDriver在Firefox,Chrome,PhantomJS中保存页面? [英] How to save page in Firefox, Chrome, PhantomJS with selenium webdriver?

查看:285
本文介绍了如何使用Selenium WebDriver在Firefox,Chrome,PhantomJS中保存页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想保存一个网站并将文件下载到特定的文件夹中.我该如何使用webdriver? 在Chrome和Firefox中,我只需按 Ctrl + S ,然后选择一个文件夹即可保存当前网站.硒webdriver中有什么办法吗? PhantomJS可以做到吗?

I want to save a web site and download file into specific folder. How can I do it with webdriver? In Chrome and Firefox I just press Ctrl+S then select a folder to save the current website. Is there any way to do it in selenium webdriver? Can PhantomJS do it?

推荐答案

自动按Control S,然后切换到保存菜单并保存html文件.这是我使用Python的方法:

Automate pressing Control S then switch to the save menu and save the html file. Here's how I did it with Python:

    driver.send_keys("u'\ue009'"+"s")
    driver.switch_to.window("Window_ID")
    driver.find_element_by_id("SAVE_button").click()

使用检查工具找到窗口名称和必要的ID.

Use the inspect tool to find the Window name and the necessary Id's.

请参阅: http://selenium- python.readthedocs.org/api.html#selenium.webdriver.common.keys.Keys.CONTROL

这篇关于如何使用Selenium WebDriver在Firefox,Chrome,PhantomJS中保存页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆