没有加载所有页面源PHP

时间:2014-01-07 11:47:10

标签: php curl

我正在尝试使用curl调用获取网站源代码但有些数据丢失了,我不知道我做错了什么。 如果我在页面源代码中调用浏览器中的网址,则会出现<!-- request captchas: blabla --> .. 但是在我用php调用之后它将引入页面源:"<!-- request captchas: null -->" 我的代码:

$url='http://www.anaf.ro/anaf/internet/ANAF/informatii_publice/informatii_agenti_economici/registrul_inactivi_reactivati/';
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0)         Gecko/20100101 Firefox/18.0");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_COOKIE, "JSESSIONID=0001R8jflCwCXeYrmbF45vBxtS-:3KMDRVUOUV");
curl_setopt($ch, CURLOPT_URL, $url);
$html = curl_exec($ch);
curl_close ($ch);
echo $html;

2 个答案:

答案 0 :(得分:0)

您忘了添加curl_init()

这样做..

<?php
$url='http://www.anaf.ro/anaf/internet/ANAF/informatii_publice/informatii_agenti_economici/registrul_inactivi_reactivati/';
$ch = curl_init(); //<-------------- Add this here
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0)         Gecko/20100101 Firefox/18.0");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_COOKIE, "JSESSIONID=0001R8jflCwCXeYrmbF45vBxtS-:3KMDRVUOUV");
curl_setopt($ch, CURLOPT_URL, $url);
$html = curl_exec($ch);
curl_close ($ch);
echo $html;

答案 1 :(得分:0)

尝试删除此行:

curl_setopt($ch, CURLOPT_COOKIE, "JSESSIONID=0001R8jflCwCXeYrmbF45vBxtS-:3KMDRVUOUV");