繁体   English   中英

在命令行和PHP代码中使用curl调用带有参数的URL

[英]Invoke an url with parameters using curl from command line and in a PHP code

我必须在我的Ubuntu 15.10中调用此网址...

http://listeps.cittadellasalute.to.it/?id=01090101

从命令行和PHP使用curl

我注意到,如果我只是提交,就不会考虑任何参数

curl 'http://listeps.cittadellasalute.to.it/?id=01090101'

您可以注意到结果中没有数字,与提交时的行为完全相同

curl 'http://listeps.cittadellasalute.to.it/'

同样使用此PHP代码

<?php
    ini_set('display_errors', 1);

    $url = 'http://listeps.cittadellasalute.to.it/?id=01090101';


    //#Set CURL parameters: pay attention to the PROXY config !!!!
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($ch, CURLOPT_PROXY, '');
    $data = curl_exec($ch);
    curl_close($ch);

    $dom = new DOMDocument();
    @$dom->loadHTML($data);

    $xpath = new DOMXPath($dom);

    $greenWaitingNumber = $xpath->query('/html/body/div/div/div[4]/div[3]/section/p');


    foreach( $greenWaitingNumber as $node )
    {
      echo "Number first green line: " .$node->nodeValue;
      echo '<br>';
      echo '<br>';
    }


?>

如何在命令行和PHP代码中使用curl来使用url参数?

从邮递员导出将导致类似这样的结果

curl -X GET 'http://listeps.cittadellasalute.to.it/?id=01090101'

您还可以查看本教程https://www.getpostman.com/docs/postman/sending_api_requests/generate_code_snippets

该网站提出AJAX请求

你什么都没弄乱。 html首先是空的,然后加载code.js,这会向ID为gtotal.php的请求。 如果您在chrome开发工具中打开“网络”标签,就可以看到所有这些信息。

要获取数据:

curl http://listeps.cittadellasalute.to.it/gtotal.php?id=01090101

已发送参数,但javascript部分从不运行。

暂无
暂无

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

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