Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
关于php curl和curl命令_Php_Curl - Fatal编程技术网

关于php curl和curl命令

关于php curl和curl命令,php,curl,Php,Curl,Php curl返回一些站点的空白页,其中curl命令工作正常 例如:curl www.wikipedia.org生成输出,而php curl提供带有标记的空白页面 您可以使用以下代码执行此操作: <?php $debug = 1; $fb_page_url = "http://www.wikipedia.org"; $cookies = 'cookies.txt'; touch($cookies); $uagent = 'Mozilla/5.0 (X11; Linux x86_64)

Php curl返回一些站点的空白页,其中curl命令工作正常

例如:curl www.wikipedia.org生成输出,而php curl提供带有标记的空白页面


您可以使用以下代码执行此操作:

<?php

$debug = 1;
$fb_page_url = "http://www.wikipedia.org";
$cookies = 'cookies.txt';
touch($cookies);
$uagent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/36.0.1985.125 Chrome/36.0.1985.125 Safari/537.36';


/**
    Get __VIEWSTATE & __EVENTVALIDATION
 */
$ch = curl_init($fb_page_url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $uagent);

$html = curl_exec($ch);

curl_close($ch);

preg_match('~<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="(.*?)" />~', $html, $viewstate);
preg_match('~<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="(.*?)" />~', $html, $eventValidation);

$viewstate = $viewstate[1];
$eventValidation = $eventValidation[1];



/**
 Start Fetching process
 */
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $fb_page_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 9850);
curl_setopt($ch, CURLOPT_USERAGENT, $uagent);

// Collecting all POST fields
$postfields = array();
//$postfields['__EVENTTARGET'] = ""; //this is for further clicking any link
//$postfields['__EVENTARGUMENT'] = ""; //this is for further clicking any link
$postfields['__LASTFOCUS'] = "";
$postfields['__VIEWSTATE'] = $viewstate;
$postfields['__EVENTVALIDATION'] = $eventValidation;
$postfields['hidStates'] = "";

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$ret = curl_exec($ch); // Get result as fetched web page.

    if ($debug) {
        echo $ret;
    }
    curl_close($ch);
?>

您可以使用以下代码执行此操作:

<?php

$debug = 1;
$fb_page_url = "http://www.wikipedia.org";
$cookies = 'cookies.txt';
touch($cookies);
$uagent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/36.0.1985.125 Chrome/36.0.1985.125 Safari/537.36';


/**
    Get __VIEWSTATE & __EVENTVALIDATION
 */
$ch = curl_init($fb_page_url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $uagent);

$html = curl_exec($ch);

curl_close($ch);

preg_match('~<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="(.*?)" />~', $html, $viewstate);
preg_match('~<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="(.*?)" />~', $html, $eventValidation);

$viewstate = $viewstate[1];
$eventValidation = $eventValidation[1];



/**
 Start Fetching process
 */
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $fb_page_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 9850);
curl_setopt($ch, CURLOPT_USERAGENT, $uagent);

// Collecting all POST fields
$postfields = array();
//$postfields['__EVENTTARGET'] = ""; //this is for further clicking any link
//$postfields['__EVENTARGUMENT'] = ""; //this is for further clicking any link
$postfields['__LASTFOCUS'] = "";
$postfields['__VIEWSTATE'] = $viewstate;
$postfields['__EVENTVALIDATION'] = $eventValidation;
$postfields['hidStates'] = "";

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$ret = curl_exec($ch); // Get result as fetched web page.

    if ($debug) {
        echo $ret;
    }
    curl_close($ch);
?>

让你分配$url=www.wikipedia.org;让你分配$url=www.wikipedia.org;通过提供eventtarget和eventargument,您还可以单击任何链接(如果需要)。我想这可能会对你有所帮助。这绝对不是在回答这个问题。。。这看起来就像是将某个curl请求随机复制粘贴到特定页面。我的意思是:为什么curl_setopt$ch,CURLOPT_TIMEOUT,9850;甚至在这里产生影响?op没有报告超时问题,为什么要将其设置得如此之高?通过提供eventtarget和eventargument,您还可以单击任何链接(如果需要)。我想这可能会对你有所帮助。这绝对不是在回答这个问题。。。这看起来就像是将某个curl请求随机复制粘贴到特定页面。我的意思是:为什么curl_setopt$ch,CURLOPT_TIMEOUT,9850;甚至在这里产生影响?op没有报告超时问题,为什么要将其设置得如此之高?