我可以使用HTMLUnit访问HTML5存储吗? [英] Can I access HTML5 storages using HTMLUnit

查看:304
本文介绍了我可以使用HTMLUnit访问HTML5存储吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要确定是否有任何页面存储或从HTML5数据存储中读取。我正在使用HTMLUnit来浏览网页。我查看了sourceforge列表中已经构建了对HTML5存储的支持。 HTMLUnit是否实际为localStorage,sessionStorage等创建了对象?如果是,我该如何访问它们?

I've a requirement where I need to identify if any page is storing or reading from HTML5 data stores. I am using HTMLUnit to scrape through webpages. I checked in the sourceforge listing that the support for HTML5 storages has been built. Does HTMLUnit actually create objects for localStorage, sessionStorage etc? If yes, how can I access them?

我还想过在页面上抓取所有Javascripts并搜索关键字,但有没有比这更好的方法?

I've also thought of scraping all Javascripts on the page and search for the keywords, but is there any better method than that?

推荐答案

一个简单的测试可能是传递一个执行setItem的javascript源代码('key','value')存储然后执行getItem('key')并检查结果。如果返回某个脚本对象,则表示成功。如下所示:

a simple test could be to pass a javascript source code that does the setItem('key','value') storage and then does getItem('key') and inspect the result. If some script object is returned, it means success. something like the following:

ScriptResult result = currentPage.executeJavaScript("window.localStorage.setItem('some_key','some_value');window.localStorage.getItem('some_key');");
System.out.println("script result: "+result.getJavaScriptResult().toString());

这篇关于我可以使用HTMLUnit访问HTML5存储吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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