cURL出错 - “无法解析主机:www.bbb.org(;没有请求类型的数据记录”)

时间:2010-07-19 10:44:30

标签: php curl web-scraping

我正在尝试使用cURL访问http://www.bbb.org/us/Find-Business-Reviews/的数据。现在我使用HTTPFox来查看此站点发送的数据,并相应地将一个数组“POST”到页面。但是我在访问页面2,3,4,5 ...

时遇到了问题

这是数组 -

$array = Array();
 $array['__EVENTTARGET'] = 'ctl12$gc1$s$gridResults$ctl23$pagerLinkButton2';
 $array['__EVENTARGUMENT'] = '';
 $array['__LASTFOCUS'] = '';
 $array['__VIEWSTATEFIELDCOUNT'] = 6;
 $array['__VIEWSTATE']  = $View_state;
 $array['__VIEWSTATE1'] = $View_state1;
 $array['__VIEWSTATE2'] = $View_state2;
 $array['__VIEWSTATE3'] = $View_state3;
 $array['__VIEWSTATE4'] = $View_state4;
 $array['__VIEWSTATE5'] = $View_state5;
 $array['ctl12$qn$quickSearch'] = "";
 $array['ctl12$qn$TextBoxWatermarkExtender1_ClientState'] = "";
 $array['ctl12$gc1$s$txtSearch'] = "tax";
 $array['ctl12$gc1$s$CityTextBox'] = "";
 $array['ctl12$gc1$s$ddlState'] = "";
 $array['ctl12$gc1$s$ZipTextBox'] = 10292; 
 $array['ctl12$gc1$s$ddlSort'] = "SCORE DESC";

但我总是得到同样的错误 -

  

“无法解析主机:www.bbb.org(;没有请求类型的数据记录”

这是我正在使用的cURL功能

function cURL($url, $header=NULL, $p=NULL) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_HEADER, $header);
        curl_setopt($ch, CURLOPT_NOBODY, $header);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
        curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        if ($p) {
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $p);
        }
        $result = curl_exec($ch);
        if ($result) {
            return $result;
        } else {
            return curl_error($ch);
        }
        curl_close($ch);
    }

2 个答案:

答案 0 :(得分:2)

你认为这里引用的网址没有错吗? :)

Could not resolve host: www.bbb.org(;

答案 1 :(得分:0)

可能与您的问题没什么关系,但是:

        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POST, 1);

是重复的。通过设置CURLOPT_POST,你已经告诉curl你正在发帖子。 CUSTOMREQUEST用于执行不常见的HTTP请求,例如'HEAD',标准CURL函数调用不存在。