Javascript casperjs(phantomjs)无法在网站更新后提交表单
我已经有一个脚本运行了一段时间,直到最近在一个网站更新之后 我所做的是填写表格,点击提交并删除结果 现在看来无论我做什么,点击,发送一个回车键。。等等,表格不会提交 我从casper获得了以下调试行:Javascript casperjs(phantomjs)无法在网站更新后提交表单,javascript,jquery,forms,phantomjs,Javascript,Jquery,Forms,Phantomjs,我已经有一个脚本运行了一段时间,直到最近在一个网站更新之后 我所做的是填写表格,点击提交并删除结果 现在看来无论我做什么,点击,发送一个回车键。。等等,表格不会提交 我从casper获得了以下调试行: casperjs casper1.js [info] [phantom] Starting... [info] [phantom] Running suite: 4 steps [debug] [phantom] opening url: https://www.vicroads.vic.gov
casperjs casper1.js
[info] [phantom] Starting...
[info] [phantom] Running suite: 4 steps
[debug] [phantom] opening url: https://www.vicroads.vic.gov.au/registration/buy-sell-or-transfer-a-vehicle/buy-a-vehicle/check-vehicle-registration/vehicle-registration-enquiry, HTTP GET
[debug] [phantom] Navigation requested: url=https://www.vicroads.vic.gov.au/registration/buy-sell-or-transfer-a-vehicle/buy-a-vehicle/check-vehicle-registration/vehicle-registration-enquiry, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "https://www.vicroads.vic.gov.au/registration/buy-sell-or-transfer-a-vehicle/buy-a-vehicle/check-vehicle-registration/vehicle-registration-enquiry"
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step anonymous 2/4 https://www.vicroads.vic.gov.au/registration/buy-sell-or-transfer-a-vehicle/buy-a-vehicle/check-vehicle-registration/vehicle-registration-enquiry (HTTP 200)
[info] [phantom] Step anonymous 2/4: done in 1579ms.
[info] [phantom] Step _step 3/5 https://www.vicroads.vic.gov.au/registration/buy-sell-or-transfer-a-vehicle/buy-a-vehicle/check-vehicle-registration/vehicle-registration-enquiry (HTTP 200)
[info] [phantom] Step _step 3/5: done in 1599ms.
[info] [phantom] waitFor() finished in 40ms.
[info] [phantom] Step anonymous 4/5 https://www.vicroads.vic.gov.au/registration/buy-sell-or-transfer-a-vehicle/buy-a-vehicle/check-vehicle-registration/vehicle-registration-enquiry (HTTP 200)
[debug] [phantom] Mouse event 'mousedown' on selector: form#form1
[debug] [phantom] Mouse event 'mouseup' on selector: form#form1
[debug] [phantom] Mouse event 'click' on selector: form#form1
[info] [phantom] Step anonymous 4/5: done in 1691ms.
[info] [phantom] Step anonymous 5/5 https://www.vicroads.vic.gov.au/registration/buy-sell-or-transfer-a-vehicle/buy-a-vehicle/check-vehicle-registration/vehicle-registration-enquiry (HTTP 200)
[debug] [phantom] Capturing page to /var/www/html/poc/phantom/test.png
[info] [phantom] Capture saved to /var/www/html/poc/phantom/test.png
[info] [phantom] Step anonymous 5/5: done in 1964ms.
[info] [phantom] Done 5 steps in 1967ms
[debug] [phantom] Capturing page to /var/www/html/poc/phantom/test0.png
[info] [phantom] Capture saved to /var/www/html/poc/phantom/test0.png
[debug] [phantom] Navigation requested: url=about:blank, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "about:blank"
我还尝试等待包含结果的选择器,但它从未到达
任何phantomjs/casperjs大师都有什么诀窍吗?你不是在点击提交按钮,而是在点击整个表单
this.click('form#form1');
处方集不是按钮,因此不能“点击”。您应该查找submit按钮并单击它。在这种情况下,我会这样做:
this.click('"#main input[type='submit']"');
就这样
使用'form#form1'
这一您实际上正在寻找的submit
功能,但我认为直接在表单上调用submit
不会触发附加到按钮的onClick
事件,因此如果您想要100%模拟用户操作,单击按钮比直接提交表单更好
要直接提交表单,只需删除
fill
方法末尾的false
属性。感谢您的时间,我们将尝试一下。我的另一个想法是使用禁用javascript的phantomjs版本。@Vivvi-Woah,一个“低谷”用户说“谢谢你的时间”。现在在这里这很难,我很感激。因为waitfor('element')不起作用,我认为等待不会有任何影响。我的另一个想法是通过在无头浏览器中禁用javascript来消除这些事件。waitFor(“element”)
donothingwaitFor
是接受将运行自定义检查的函数。对于waitFor…
(注意点)方法,我所说的都是waitForUrl
,waitForResource
,等等。。。或者使用自己的函数包含waitFor()
,但您必须具有创造性。例如,添加一个事件侦听器,该侦听器将在每次更改url时调用,并使用一个检查url是否已加载的函数调用callwaitFor
。顺便说一句,这不是一个单行修复程序。另外,正如你所说,你可以尝试禁用JS,但有些网站不能正常工作。尝试在浏览器中禁用它,并检查它是否加载。如果可行,它将是一个更快、更少消耗资源的解决方案。
this.click('"#main input[type='submit']"');