javascript 使用curl单击javascript按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10937646/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
javascript button click using curl
提问by qmaruf
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.
我使用 curl 解析了一个页面,它包含一些复选框和一个“全选”和一个“提交”按钮。单击该按钮会选择每个复选框。“全选”按钮会触发一个 javascript 函数,该函数实际上选择所有复选框。
Now i need to click 'select all' and 'submit' button.How can I do this ??
现在我需要点击“全选”和“提交”按钮。我该怎么做??
Here is the button code:
这是按钮代码:
input type="button" onclick="SelectAll(137)" value="Select All"
Here is the js function:
这是js函数:
function SelectAll(n)
{
for(i=0;i<n;i++)
document.getElementById("ch"+i).checked=true;
}
回答by Jonathan S.
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-curlfor a general example of a POST request through cURL with PHP.
你不能。如果必须使用 cURL,则必须自己手动制作 POST 请求。这将涉及查找所有复选框的名称并checkbox1=on&checkbox2=on&...
在 POST 正文中发送一堆。请参阅http://davidwalsh.name/execute-http-post-php-curl以了解通过 cURL 使用 PHP 进行 POST 请求的一般示例。
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.
另一种选择是使用Selenium Web Driver 之类的东西,它几乎允许您编写可以运行 JavaScript、单击内容等的 Firefox 等 Web 浏览器的脚本。
回答by bluedevil2k
Pass a parameter in with your Curl request that gets parsed by jQuery on its $(document).ready(). There's some plugins that help with parsing parameters.
将参数与您的 Curl 请求一起传递,该参数由 jQuery 在其 $(document).ready() 上解析。有一些插件可以帮助解析参数。
Something like
就像是
$(document).ready(function(){
var buttonPress = $.param("buttonPress");
if (buttonPress == true)
$("#myButton").click();
});