使用 mechanize 勾选复选框

发布于 2024-12-07 13:48:59 字数 589 浏览 0 评论 0原文

我从这个网站得到了以下 html 片段: http://catalogue.bl.uk/F/NTBK6NCP3LK56BPNU2NJ4FF4MBLIRUNMFX66JLHKBDV1RNCAAB-02920?func=short-0&set_number=151530

<form name="XXX000001" method="GET"><input type="checkbox" name="ckbox"   onclick="javascript:select_record(this.form);" onkeypressed="javascript:select_record(this.form);"></form>

我想知道是否可以使用 mechanize 来勾选复选框?这些框似乎不是使用普通的 html 形成的。我不懂 JavaScript

I have the following html piece from this website:
http://catalogue.bl.uk/F/NTBK6NCP3LK56BPNU2NJ4FF4MBLIRUNMFX66JLHKBDV1RNCAAB-02920?func=short-0&set_number=151530

<form name="XXX000001" method="GET"><input type="checkbox" name="ckbox"   onclick="javascript:select_record(this.form);" onkeypressed="javascript:select_record(this.form);"></form>

I was wondering if there is anyway I can use mechanize to tick the checkboxes? It seems that these boxes are not formed using the normal html. I don't know javascript

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

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

发布评论

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

评论(4

吝吻 2024-12-14 13:48:59

也许你应该检查 WWW::Selenium 以便处理 JavaScript 网页。

WWW::Selenium 是一种浏览器远程控制。
从文档中可以看出:Selenium Remote Control (SRC) 是一个测试工具,允许您使用任何支持 JavaScript 的主流浏览器以任何编程语言针对任何 HTTP 网站编写自动化 Web 应用程序 UI 测试。
SRC提供了一个Selenium Server,它可以自动启动/停止/控制任何支持的浏览器。它通过使用 Selenium Core 来工作,Selenium Core 是一个纯 HTML+JS 库,可以在 JavaScript 中执行自动化任务; Selenium 服务器使用 AJAX (XmlHttpRequest) 直接与浏览器通信。

下载并安装 Selenium 服务器(一个 Java 应用程序)后,您可以使用模块 WWW::Seletion,控制服务器,该服务器将使用浏览器与支持 JavaScript 的复杂网站进行交互。

通过类 WWW::Selenium 的实例,

my $sel = WWW::Selenium->new(
    host => "localhost",
    port => 4444,
    browser => "*iexplore",
    browser_url => "http://www.google.com",
);

几乎所有与网站的交互都成为可能。必须定义一个定位器来精确定位页面中的元素,以便发出命令(选择、单击等)。

您将在模块文档中找到详细的帮助。

Maybe you should check WWW::Selenium in order to deal with JavaScript web pages.

WWW::Selenium is a kind of remote control for browsers.
From the documentation: Selenium Remote Control (SRC) is a test tool that allows you to write automated web application UI tests in any programming language against any HTTP website using any mainstream JavaScript-enabled browser.
SRC provides a Selenium Server, which can automatically start/stop/control any supported browser. It works by using Selenium Core, a pure-HTML+JS library that performs automated tasks in JavaScript; the Selenium Server communicates directly with the browser using AJAX (XmlHttpRequest).

After you have downloaded and installed the Selenium server ( a Java apllication ), you can use the module WWW::Seletion, to control the server which will use browsers to interact with complex JavaScript enabled web sites.

With an instance of the class WWW::Selenium

my $sel = WWW::Selenium->new(
    host => "localhost",
    port => 4444,
    browser => "*iexplore",
    browser_url => "http://www.google.com",
);

almost every kind of interaction with a web site become possible. One has to define a locator to pinpoint an element in the page, in order to issue a command ( select, click, ... ).

You'll find detailed help in the module documentation.

匿名。 2024-12-14 13:48:59

我假设您正在讨论使用 Mechanize 将信息提交回页面,就像人类使用浏览器勾选复选框一样。最简单的方法是首先使用 WireShark 来观察当您实际使用 Web 浏览器提交表单(选中复选框)时发生的所有情况,然后在使用 Perl 提交表单时模仿相同的行为。

I assume you're talking about submitting information back to the page using Mechanize as if a human was using a browser to tick the checkboxes. The easiest way to do this is to first use WireShark to watch everything that happens when you actually submit the form with a web browser (with the checkboxes checked) and then mimic that same behavior when you submit the form using Perl.

自找没趣 2024-12-14 13:48:59

因为 WWW::Mechanize 不会讲 javascript,所以您要么需要按照建议进行操作并弄清楚 javascript 的作用并绕过它的后面,要么您可以使用类似 WWW::Mechanize::Firefox 允许您控制浏览器。

Because WWW::Mechanize does not speak javascript, you either need to do as suggested and figure out what the javascript does and go around its back or you can use something like WWW::Mechanize::Firefox that will allow you to control a browser.

撕心裂肺的伤痛 2024-12-14 13:48:59

我有一个建议,诚然不是最优雅的解决方案,但本着“完成”的精神,您可以尝试创建一个 autoit 脚本,为您完成一些 GUI 交互。这是一个非常简洁的小工具。我厌倦了在游戏中升级我的角色,所以我创建了一个自动脚本来为我升级我的玩家,我只花了大约一天的时间来学习语法和创建脚本。我确信自动化网页会花费更少的时间。只是一个想法...

I have a suggestion that is admittedly not the most elegant solution but in the spirit of "gett'r done" you could try and create an autoit script that did some of the gui interactions for you. It is pretty neat little tool. I was bored of leveling my character in a game once so I created an autoit script to level my player for me and it only took me about a day to learn the syntax and create the script. I am sure automating a webpage would take much, much less time. Just a thought...

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