硒-保存网站,包括所有图像,CSS,DOM [英] Selenium - Save website including all images, css, dom
问题描述
我想使用Firefox或chrome浏览带有硒的页面。加载页面后,我想从页面下载所有图像,css,dom。
I would like to visit a page with selenium using firefox or chrome. When the page is loaded I would like to download all images, css, dom from the page.
我想存储每个图像,就像在其中找到它们一样:
I would like to store every image like I find them in:
chrome -> Tools->Development Tools -> Resources -> Images
是否可以通过硒访问并保存所有内容?
Is it possible to get access via selenium and save everything?
到目前为止,我仅找到此页面,对我而言没有任何有趣的提示:
> http://ldanswers.org/wordpress/zisser/2014/11/24/save-whole- web-page-with-all-resources-in-selenium-webdriver /
So far I only found this page, which has no interesting hints for me: http://ldanswers.org/wordpress/zisser/2014/11/24/save-whole-web-page-with-all-resources-in-selenium-webdriver/
推荐答案
我找到了解决方案我自己的问题。问题是,当您单击另存为-> STRG + S时,会弹出一个OS窗口,该窗口无法由Selenium管理。我了解了许多使用AutoIT,xnee,jna或Java Robot等工具解决此问题的方法。
I found a solution to the problem by myself. The Problem is when you click on Save page as -> STRG + S an OS-Window pops up, which can't be managed by Selenium. I read about many possible solutions about that using tools like AutoIT, xnee, jna or Java Robot.
我不想使用此类工具。因此,我搜索了可以下载整个页面(包括图像,css,html)的firefox插件。几秒钟后,我发现了剪贴簿。
I didn't wanted to use such tools. So I searched for a firefox addon which is able to download a whole page (including images, css, html). After some seconds I found Scrapbook.
最后,我下载了Addon File scrapbook-1.5.11-fx.xpi,修改了其中的一些值并与硒一起使用。
At last I downloaded the Addon File scrapbook-1.5.11-fx.xpi, modified some values in it and used it with selenium. It is working very vell.
我在 /defaults/preferences/scrapbook-prefs.js 处更改的值是
pref("scrapbook.data.default", false);
pref("scrapbook.data.path", "/Path/to/store/webpage");
pref("scrapbook.key.save", "D");
此配置告诉剪贴簿将网页保存在定义的路径中,并且保存页面的快捷方式是 STRG + SHIFT + D 。
This config tells scrapbook to save the webpages at the defined path and that the shortcut for saving a page is STRG + SHIFT + D.
现在,您只需要将插件添加到firefox配置文件中,调用网站并将快捷方式发送到浏览器即可。
Now you only have to add the Plugin to the firefox profile,call a website and Send the shortcut to the browser.
FirefoxProfile oProfile = new FirefoxProfile();
File extension = new File("scrapbook-1.5.11-fx.xpi");
try {
oProfile.addExtension(extension);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
WebDriver driver = new FirefoxDriver(oProfile);
driver.get("https://google.com");
new Actions(driver).sendKeys(Keys.chord(Keys.CONTROL,Keys.SHIFT, "D")).perform();
我希望这对某人有帮助!
I hope this helps someone!
编辑:如果您希望剪贴簿也默认保存JavaScript,则必须在插件中更改文件saver.js并将值 script:false设置为true。
If you want scrapbook to also save JavaScript per Default you have to change the file saver.js in the Plugin and set the value "script" : false to true.
这篇关于硒-保存网站,包括所有图像,CSS,DOM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!