努力点击 htmlunit 中的链接

发布于 2024-10-21 03:44:12 字数 975 浏览 2 评论 0原文

我在点击 htmlunit 中的链接时遇到问题。我浏览了网站上的 api(我不太理解)并查看了我能找到的所有示例代码,但在单击链接时仍然遇到问题。

这是错误消息的顶部(它非常大,如果您愿意,我可以全部提交)

"page2 = link2.click() Exception class=[net.sourceforge.htmlunit.corejs.javascript.JavaScriptException] com.gargoylesoftware.htmlunit.ScriptException: Sys.ArgumentOutOfRangeException: Sys.ArgumentOutOfRangeException: Value must be an integer. Parameter name: x Actual value was Infinity. "

第一页加载正常,但是当我单击第二个链接时,我收到此错误(链接是 javascript)。这是我的代码的一部分

       page = webclient.getPage(url) 
   anchors1 =  page.getAnchors()
   for anchor in anchors1:
        if anchor.asText() == "2":
            link2 = anchor
            break
   page2 = link2.click()

如果我执行打印链接2,我会得到: HtmlAnchor[]

起初我认为 HtmlAnchor 可能是一个问题,我必须将其删除,但后来我查看了其他示例代码,它们的链接似乎以相同的格式结束,并且它可以工作。

很困惑..请帮忙:-)

提前致谢!

I am having a problem clicking on a link within htmlunit. I went through the api on the site(which I didn't really understand well) and looked at all the sample code I could find and am still having a problem with clicking on links.

Here's the top of the error messsage(its pretty large, if you want I can submit it all)

"page2 = link2.click() Exception class=[net.sourceforge.htmlunit.corejs.javascript.JavaScriptException] com.gargoylesoftware.htmlunit.ScriptException: Sys.ArgumentOutOfRangeException: Sys.ArgumentOutOfRangeException: Value must be an integer. Parameter name: x Actual value was Infinity. "

The first page loads fine but when I click on the second link, I get this error(the link is javascript). Here's parts of my code

       page = webclient.getPage(url) 
   anchors1 =  page.getAnchors()
   for anchor in anchors1:
        if anchor.asText() == "2":
            link2 = anchor
            break
   page2 = link2.click()

If I do a print link2 I get: HtmlAnchor[<a href="javascript:__doPostBack('ctl00$MainContent$gvSearchResults','Page$2')">]

At first I thought maybe the HtmlAnchor was a problem and I had to remove it but then I looked at other sample code and they seem to have their links end up in the same format and it works.

So confused..please help :-)

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

滴情不沾 2024-10-28 03:44:12

问题不在于用于单击链接的代码。它位于单击链接时执行的 JavaScript 中。要么 JavaScript 有错误,要么 HtmlUnit 使用的 JavaScript 解释器运行时出现问题。

问题似乎出在参数 x 上,该参数在执行期间具有无穷大值。

The problem is not in the code used to click on the link. It's in the JavaScript executed when the link is clicked. Either the JavaScript is buggy, or the JavaScript interpreter used by HtmlUnit has a problem running it.

The problem seems to be with a parameter x which has the Infinity value during the execution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文