想抓移动官网的优惠列表,是js动态ajax提交获取的内容,在本地根据参数写个post表单可以正常提交获取到内容,根据修改页数的参数可以获取到不同页的内容,不是获取,内容显示的页面还是在移动官网提交的地址。 用curl模拟post的提交,那边就获取不到参数,不能根据页数获取到内容用curl提交到本地的接收测试页面,可以收到post数据。。这是为什么呢,是因为移动官网做了防抓取吗。。求大神帮忙看看。http://gd.10086.cn/peting/preferential/common/index/preferencelist.jsps(这是ajax请求地址)参数:
currPage:2(页数)
queryCityCodeId:SZ(各市的首拼音大写)
queryBrandCodeId:(空)
queryTypeId:(空)
queryRange:(空)
queryByAssigned:(空)
queryKeyWord:(空)phpcurl移动表单ajax

解决方案 »

  1.   

    4Uncaught ReferenceError: movepage is not defined 
      

  2.   

        $url = "http://gd.10086.cn/peting/preferential/common/index/preferencelist.jsps";   echo get_curlcuconent2($url,"http://gd.10086.cn/peting/preferential/index.jsp");
        
        function get_curlcuconent2($filename,$referer)
        {
         $cookie_jar = tempnam('./temp','JSESSIONID');
         $header = array (
         "Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
         "Cache-Control:no-cache",
         "Content-Length:103",
         "Content-Type:application/x-www-form-urlencoded",
         "Host:gd.10086.cn",
         "Origin:http://localhost",
         "Referer:http://localhost/",
         );
         $post_data = array (
         "currPage"         => "5",
         "queryCityCodeId"  => "SZ",
         "queryBrandCodeId" => "",
         "queryTypeId"      => "",
         "queryRange"       => "",
         "queryByAssigned"  => "",
         "queryKeyWord"     => ""
         );
          
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $filename);
         curl_setopt($ch, CURLOPT_HEADER, false);
         curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        
         curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);
         $filecontent=curl_exec($ch);
         curl_close($ch);
          
         $ch = curl_init();
         $hostname ="gd.10086.cn";
         //$referer="http://www.domain.com/";
         curl_setopt($ch, CURLOPT_URL, $filename);
    //      curl_setopt($ch, CURLOPT_REFERER, $referer);
    //      curl_setopt($ch, CURLOPT_USERAGENT, "gd.10086.cn");     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar);
         curl_setopt($ch, CURLOPT_HEADER, false);
         curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        
         $filecontent = curl_exec($ch);
    //      preg_match_all("/charset=(.+?)[NULL\"\']/is",$filecontent, $charsetarray);
    //      if(strtolower($charsetarray[1][0])=="utf-8")
    //      $filecontent=iconv( 'utf-8', 'gb18030//IGNORE' , $filecontent);
         curl_close($ch);
         return $filecontent;
        }
      

  3.   


    这个是优惠列表页面:http://gd.10086.cn/peting/preferential/index.jsp