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

时间:2017-08-11 20:47:39

标签: php curl

我要在我的Ubuntu 15.10中调用这个URL ...

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参数?

0 个答案:

没有答案