如何限制HtmlUnit的历史记录大小?
我正在使用 HtmlUnit 进行解析工作,我发现 WebClient 保存每个 WebWindow 的历史记录会浪费内存。我根本不使用历史记录,我想禁用其管理或至少将其大小限制为 1 或 2。这可能吗?
I'm using HtmlUnit for a parsing job and I've discovered that the memory gets wasted with the WebClient holding the history for each WebWindow. I don't use the history at all and I'd like to disable its management or at least limit its size with 1 or 2. Is that possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下代码将
ignoreNewPages_
设置为 true:访问器:
The following code will set
ignoreNewPages_
to true:The accessors:
据我所知,HtmlUnit 中没有选项可以禁用历史记录。 History 类有一个 getHistory() 方法,但没有 setHistory() 或disableHistory()。我所做的(当然并不理想)是释放网页并重新实例化它。只要您不释放 CookieManager,您在 cookie 方面就应该没问题。基本上,一旦我完成所有操作并登录,我会将当前页面存储到临时字符串后取消窗口,然后将其重新实例化到我离开的位置。我在特定点这样做是为了清除历史记录。
这允许窗口从上次停止的地方继续。
它很难看,但如果你绝望的话,它可能会起作用。
There is no option in HtmlUnit to disable history that I am aware of. The History class has a getHistory() method but no setHistory() or disableHistory(). What I have done, and it is certainly not ideal, is release the web page and reinstantiate it. As long as you don't release your CookieManager you should be ok on the cookie front. Basically once I get all the way through and logged in I nullify my window after storing the current page to a temp string, then I reinstantiate it to where I left off. I do this at given points to clear out history.
This allows the window to pick up where it left off.
Its ugly but if you are desperate, it may work.