【发布时间】:2011-10-11 23:18:45
【问题描述】:
在使用 htmlunit 抓取网页时,我偶尔会注意到类似这样的警告会淹没控制台输出。
Jul 24, 2011 5:12:59 PM com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter warning
WARNING: warning: message=[Calling eval() with anything other than a primitive string value
will simply return the value. Is this what you intended?] sourceName=[http://ad.doubleclick.net/adj/N5762.morningstar.com/B5553006.25;sz=728x90;click0=http://ads.morningstar.com/RealMedia/ads/click_lx.ads/www.morningstar.com/quicktake/fund/L34/648978540/TopLeft/Morningstar/JPM_FRpt_728x90_Jul_3827448/Fund_Reports_728x90_content.html/656d5477595534723465554144664a2b?;ord=648978540?] line=[356] lineSource=[null] lineOffset=[0]
有没有办法让 htmlunit 忽略来自
的 javascript- http://ad.*
- http://ads.*
甚至只是
同样,有没有办法让 htmlunit 只解释包含特定子字符串或匹配正则表达式的网页上的 javascript?
【问题讨论】:
-
我不相信你能做到这一点,尽管它听起来确实很有用。快速挖掘源代码并没有提供任何挂钩。另一种方法可能是告诉 Log4j 不要记录这些警告。
-
@Rodney,感谢您的提示。虽然我在原帖中没有提到这一点,但过滤 javascript 也应该可以提高性能。 htmlunit,可能会很慢,不必下载 js 文件,也不必执行更少的 javascript。
标签: java javascript screen-scraping htmlunit