dougu6815
2018-06-01 11:31
浏览 189
已采纳

PHP Curl在浏览器中返回不同的URL结果

I am using PHP Curl with this code:

curl_setopt($ch, CURLOPT_URL, 'https://www.segundamano.mx/anuncios/ciudad-de-mexico/alvaro-obregon/florida/renta-inmuebles/departamentos?precio=0-10000');
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);

curl_setopt($ch, CURLOPT_HEADER, false); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); 

//curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Firefox/22.0");

$uagent = 'Mozilla/5.0 (Windows NT 6.1; rv:22.0) Firefox/22.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';
curl_setopt($ch, CURLOPT_USERAGENT, $uagent);

curl_setopt($ch, CURLOPT_REFERER, 'http://www.google.com');
curl_setopt($ch, CURLOPT_AUTOREFERER, true); 

My question is.. why PHP Curl gives different result Than Searching URL in BROWSER?

PHP Curls gives a big BODY CONTENT... with this LINE... In Spanish... "No encontramos resultados para tu búsqueda..." In English.....There are no results for your search...

What happen with this URL? How Can I CURL and read by code this URL and get the REAL RESULTS AS BROWSER?

Help me please! Thanks!!!

图片转代码服务由CSDN问答提供 功能建议

我正在使用PHP Curl和这段代码:

  curl_setopt  ($ ch,CURLOPT_URL,'https://www.segundamano.mx/anuncios/ciudad-de-mexico/alvaro-obregon/florida/renta-inmuebles/departamentos?precio=0-10000');
curl_setopt($ch  ,CURLOPT_COOKIEJAR,$ cookies); 
curl_setopt($ ch,CURLOPT_COOKIEFILE,$ cookies); 
 
 ncurl_setopt($ ch,CURLOPT_HEADER,false);  
curl_setopt($ ch,CURLOPT_FOLLOWLOCATION,true); 
curl_setopt($ ch,CURLOPT_RETURNTRANSFER,true);  
curl_setopt($ ch,CURLOPT_SSL_VERIFYPEER,false); 
curl_setopt($ ch,CURLOPT_SSL_VERIFYHOST,false); 
curl_setopt($ ch,CURLOPT_HTTPAUTH,CURLAUTH_ANY);  
 
 // curl_setopt($ ch,CURLOPT_USERAGENT,“Mozilla / 5.0(Windows NT 6.1; rv:22.0)Gecko / 20100101 Firefox / 22.0”); 
 
 $ uagent ='Mozilla / 5.0(Windows NT 6.1)  ; rv:22.0)Firefox / 22.0(X11; Linux x86_64)AppleWebKit / 537.36(KHTML,与Gecko一样)Ubuntu Chromium / 36.0.1985.125 Chrome / 36.0.1985.125 Safari / 537.36'; 
curl_setopt($ ch,CURLOPT_USERAGENT,$ uagent)  ; 
 
 | ncurl_setopt($ ch,CURLOPT_REFERER,'http://www.google.com'); 
curl_setopt($ ch,CURLOPT_AUTOREFERER,true);  
   
 
 

我的问题是..为什么PHP Curl在浏览器中提供与搜索URL不同的结果?

PHP Curls给出了一个很大的结果 BODY CONTENT ...用这个LINE ... 西班牙语...“没有encontramos resultados paratubúsqueda...” 英语.....没有搜索结果......

这个URL会发生什么? 我如何通过代码来压缩和读取此URL并获得真正的结果作为浏览器?

请帮帮我! 谢谢! !!

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douluan5444 2018-06-01 11:44
    已采纳

    Because JavaScript is the root of all evil. the website gets the search results you want with AJAX after you've succesfully loaded the page. Just open the "network" tab of your browser inspection tool and see the requests flying around.

    Fun part: the website does have a (seemingly authorized) API that it can talk too, maybe you can try that? https://webapi.segundamano.mx/nga/api/v1.1/public

    评论
    解决 无用
    打赏 举报
  • 查看更多回答(1条)

相关推荐 更多相似问题