简体   繁体   English

使用PHP(或JS)脚本单击外部按钮

[英]Using a PHP (or JS) script to click an external button

I would like to write a PHP script which, when run, sets the values of the drop down menus on the page here and then submits these values by pressing the 'Fetch Button'. 我想编写一个PHP脚本,该脚本在运行时会在此处设置下拉菜单的值,然后通过按“提取按钮”提交这些值。

This should link to another page ( http://voyager.gsfc.nasa.gov/cgi-bin/heliopause_all ), the contents of which I would like the PHP script to return. 这应该链接到另一个页面( http://voyager.gsfc.nasa.gov/cgi-bin/heliopause_all ),我希望PHP脚本返回其内容。

I have not attempted this, since I have very limited PHP knowledge, so I ask whether this would be possible and what I would have to learn about PHP to do this? 由于我对PHP的了解非常有限,因此我没有尝试过此操作,所以我问这是否可能,并且我将必须学习有关PHP的哪些知识?

-- Edit -- -编辑-

Looking at the source code, would this be possible with simply a POST request from JavaScript? 查看源代码,仅通过JavaScript的POST请求就能做到吗?

First idea I have had. 我有第一个想法。 Make a POST with curl to: http://voyager.gsfc.nasa.gov/cgi-bin/heliopause_all 进行POST卷曲到: http : //voyager.gsfc.nasa.gov/cgi-bin/heliopause_all

with these POST-Parameters 这些POST参数

average:6hour
syear:9999
smonth:9999
sday:9999
eyear:9999
emonth:9999
eday:9999
sat:1
mnemonic:IPGH
duration:3-months
outputType:list
timeFormat:ISO

The last step is to parse the response. 最后一步是解析响应。

Code: 码:

<?php

$url = 'http://voyager.gsfc.nasa.gov/cgi-bin/heliopause_all';
$parameters_str = '';
$parameters = array(
    'average'=>'6hour',
    'syear'=>'9999',
    'smonth'=>'9999',
    'sday'=>'9999',
    'eyear'=>'9999',
    'emonth'=>'9999',
    'eday'=>'9999',
    'sat'=>'1',
    'mnemonic'=>'IPGH',
    'duration'=>'3-months',
    'outputType'=>'list',
    'timeFormat'=>'ISO'
);

foreach ($parameters as $k => $v) {
    $parameters_str .= $k . '=' . $v . '&';
}
rtrim($parameters_str, '&');


$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, count($parameters));
curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters_str);
curl_setopt($ch, CURLOPT_HEADER, false);


$result = curl_exec($ch);

curl_close($ch);

echo $result;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM