views:

97

answers:

2

I am trying to access data of http://www.bbb.org/us/Find-Business-Reviews/ with cURL. Now I used HTTPFox to see what data does this site send and accordingly made an array to "POST" to the page. But I am having problem in accessing Page 2,3,4,5...

Here is the array -

$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";

But I am always getting the same error - "Could not resolve host: www.bbb.org(; No data record of requested type"

Here is the cURL function I am using

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  A: 

Do you see nothing wrong with the URL quoted here? :)

Could not resolve host: www.bbb.org(;
Pekka
No It is the same error which is occuring. I copy pasted it!
Shubham
More explicit: that is NOT a valid domain name :)
Wrikken
@All - But I am sending initial request to the site then it is working and it shows ads, the problem is only when I try to access 2,3,4,5...Pages.
Shubham
@Shubham It doesn't matter: The URL gets broken at some point. You need to do some debugging to find out why (We can't see where `$url` comes from).
Pekka
@pekka $url is simply this - http://www.bbb.org/us/Find-Business-Reviews/ I used HTTPFox to find out where data is sent and it is this page only.
Shubham
@Shubham but in the subsequent 2,3,4,5... accesses? Can you confirm by echo()ing $url that it is correct there as well?
Pekka
The problem is when I try to access 2,3,4 pages. Actually the site is runs very wierd mechanism. It sends highly complex data to access those pages. So they arent just href links. When I try to replicate the same data to be sent this error occurs. URl is just static the one I mentioned.
Shubham
@Shubham well it looks like at some point, some URL gets scrambled with `(;`. You'll need to find out where.
Pekka
A: 

Probably not really anything to do with your problem, but:

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

is duplicative. By setting CURLOPT_POST, you're already telling curl you're doing a post. CUSTOMREQUEST is for doing uncommon HTTP requests, like 'HEAD', for which a standard CURL function call doesn't exist.

Marc B