使用curl点击javascript按钮 [英] javascript button click using curl
问题描述
我使用curl解析了一个页面,它包含一些复选框和一个'select all'和一个'submit'按钮。单击按钮选中每个复选框。选择全部按钮触发一个实际选中所有复选框的javascript函数。
I have parsed a page using curl and it contains some check box and a 'select all' and a 'submit' button . Clicking the button selects every check box.'select all' button triggers a javascript function which actually select all check box.
现在我需要点击全选和提交'按钮。我该怎么做?
Now i need to click 'select all' and 'submit' button.How can I do this ??
这是按钮代码:
input type="button" onclick="SelectAll(137)" value="Select All"
这是js函数:
function SelectAll(n)
{
for(i=0;i<n;i++)
document.getElementById("ch"+i).checked=true;
}
推荐答案
你不能。如果必须使用cURL,则必须自己手动制作POST请求。这将涉及查找所有复选框的名称,并在POST正文中发送一堆 checkbox1 = on& checkbox2 = on& ...
。请参见 http://davidwalsh.name/execute-http-post-php-curl通过cURL和PHP的POST请求的一般示例。
You can't. If you must use cURL, you'd have to manually craft the POST request yourself. This would involve finding the names of all the checkboxes and sending a bunch of checkbox1=on&checkbox2=on&...
in the POST body. See http://davidwalsh.name/execute-http-post-php-curl for a general example of a POST request through cURL with PHP.
另一种选择是使用像 Selenium Web Driver ,它几乎允许你编写像Firefox一样的网页浏览器,可以运行JavaScript,点击等等。
Another option would be to use something like Selenium Web Driver, which pretty much allows you to script a web browser like Firefox that can run JavaScript, click things, etc.
这篇关于使用curl点击javascript按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!