I have a question I can't understand....
I use CURL to this page....
https://propiedades.com/alvaro-obregon-df/departamentos-renta
My Code is this:
$ch = curl_init($uri); // Init cURL session
curl_setopt($ch, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$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);
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout );
curl_setopt( $ch, CURLOPT_TIMEOUT, $timeout );
curl_setopt( $ch, CURLOPT_MAXREDIRS, 10);
if (!is_null($postFields))
{
$arr = explode("&", $postFields);
curl_setopt($ch, CURLOPT_POST, count(sizeof($arr)));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
}
$info = curl_exec($ch);
curl_close($ch);
In my Local host $info Always HAS all HTML content... in My Remote Server (where is the hosting of my web app)... $info always is Empty. Why???
Really I don't understand what is happening?
Some ideas?
Help me please!
PD. If I use single CURL or curl_multi_exec (MULTI-CURL with array of URLs goes bad always with the page propiedades.com .. in my LOCAL XAMP Server returns HTML Content... in my Remote Server return NOTHING).
Good afternoon,
I would like to get the data FROM this website using the API, and especially ids part ( aim ) in PHP but I obtain the following error : HTTP 415 Unsupported Media Type.
The code that I'm currently using is ( Иван Ясинский ) :
function getContentCurl($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64;
rv:25.0) Gecko/20100101 Firefox/25.0');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
return $result = curl_exec($ch);
}
$url = "https://cadres.apec.fr/cms/webservices/rechercheOffre/ids";
$content = getContentCurl($url);
var_dump($content);
Does anyone have any idea to overcome this issue ? Thank for your help.
Your missing the post data. I'm not sure of your exact query but an example query is in this code:
<?php
function getContentCurl($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"activeFiltre":true,"motsCles":"","fonctions":[],"lieux":[],"pointGeolocDeReference":{},"secteursActivite":[],"typesContrat":[],"typesConvention":[],"niveauxExperience":[],"sorts":[{"type":"DATE","direction":"DESCENDING"}],"pagination":{"startIndex":0,"range":20},"typeClient":"CADRE"}');
return $result = curl_exec($ch);
}
$url = "https://cadres.apec.fr/cms/webservices/rechercheOffre/ids";
$content = getContentCurl($url);
var_dump($content);
Outputs:
string(4083) "{"totalCount":78073,"offreFilters":[{"offreFiltering":"CONTRACT_TYPE_FILTERING","offreFilterItems":[{"key":101888,"count":69550},{"key":20053,"count":120},{"key":101930,"count":2144},{"key":101887,"count":6259}]},{"offreFiltering":"CONTRACT_DURATION_FILTERING","offreFilterItems":[{"key":143691,"count":4981},{"key":143692,"count":2562},{"key":143693,"count":976}]},{"offreFiltering":"COMPANY_TYPE_FILTERING","offreFilterItems":[{"key":143684,"count":35345},{"key":143685,"count":18112},{"key":143686,"count":13180},{"key":143687,"count":11436}]},{"offreFiltering":"POSITION_STATUS_FILTERING","offreFilterItems":[{"key":143688,"count":65264},{"key":143689,"count":1629},{"key":143690,"count":11180}]},{"offreFiltering":"EXPERIENCE_FILTERING","offreFilterItems":[{"key":101881,"count":36267},{"key":20043,"count":45182},{"key":20044,"count":11797},{"key":20045,"count":11317}]},{"offreFiltering":"GEOLOCALISABLE_FILTERING","offreFilterItems":[{"key":0,"count":6088},{"key":1,"count":71985}]},{"offreFiltering":"JOB_CODE_FILTERING","offreFilterItems":[{"key":101829,"count":1360},{"key":101828,"count":19240},{"key":101831,"count":11451},{"key":101830,"count":1336},{"key":101833,"count":17141},{"key":101832,"count":10470},{"key":101835,"count":4190},{"key":101834,"count":7131},{"key":101837,"count":11231},{"key":101836,"count":1463}]},{"offreFiltering":"LOCATION_FILTERING","offreFilterItems":[{"key":102099,"count":731},{"key":99700,"count":411},{"key":799,"count":77342}]},{"offreFiltering":"NAF_CODE_FILTERING","offreFilterItems":[{"key":101761,"count":1083},{"key":101760,"count":3773},{"key":101763,"count":3607},{"key":101762,"count":11726},{"key":101765,"count":385},{"key":101764,"count":2123},{"key":101767,"count":1134},{"key":101766,"count":1757},{"key":101769,"count":621},{"key":101768,"count":169},{"key":101771,"count":332},{"key":101770,"count":1241},{"key":101773,"count":9665},{"key":101772,"count":9572},{"key":101775,"count":695},{"key":101774,"count":2410},{"key":101777,"count":1597},{"key":101776,"count":1292},{"key":101779,"count":1308},{"key":101778,"count":336},{"key":101780,"count":158},{"key":101753,"count":11418},{"key":101752,"count":1529},{"key":101755,"count":1026},{"key":101754,"count":2418},{"key":101757,"count":4055},{"key":101756,"count":1413},{"key":101759,"count":959},{"key":101758,"count":271}]},{"offreFiltering":"NIVEAU_ETUDE"},{"offreFiltering":"DUREE_STAGE","offreFilterItems":[{"key":599765,"count":381},{"key":599766,"count":233},{"key":599767,"count":710},{"key":599768,"count":441},{"key":599769,"count":280},{"key":599770,"count":2936},{"key":599771,"count":3538}]},{"offreFiltering":"DATE_PRISE_POSTE","offreFilterItems":[{"key":599777,"count":75435},{"key":599778,"count":2209},{"key":599779,"count":429}]},{"offreFiltering":"PERIOD_FILTERING","offreFilterItems":[{"key":101850,"count":11054},{"key":101851,"count":32259},{"key":101852,"count":78073},{"key":101853,"count":78073}]},{"offreFiltering":"WAGE_FILTERING","offreFilterItems":[{"key":597179,"count":7147},{"key":599738,"count":38996},{"key":101840,"count":56141},{"key":101841,"count":25697},{"key":101842,"count":6213},{"key":101843,"count":1408}]}],"resultats":[{"#uriOffre":"offre?numeroOffre=163035045W"},{"#uriOffre":"offre?numeroOffre=163035043W"},{"#uriOffre":"offre?numeroOffre=163035044W"},{"#uriOffre":"offre?numeroOffre=162918884W"},{"#uriOffre":"offre?numeroOffre=162913997W"},{"#uriOffre":"offre?numeroOffre=163035042W"},{"#uriOffre":"offre?numeroOffre=162930465W"},{"#uriOffre":"offre?numeroOffre=162926697W"},{"#uriOffre":"offre?numeroOffre=163035041W"},{"#uriOffre":"offre?numeroOffre=163035040W"},{"#uriOffre":"offre?numeroOffre=163035039W"},{"#uriOffre":"offre?numeroOffre=163035036W"},{"#uriOffre":"offre?numeroOffre=163035032W"},{"#uriOffre":"offre?numeroOffre=163035031W"},{"#uriOffre":"offre?numeroOffre=163035030W"},{"#uriOffre":"offre?numeroOffre=163035029W"},{"#uriOffre":"offre?numeroOffre=163035027W"},{"#uriOffre":"offre?numeroOffre=163035026W"},{"#uriOffre":"offre?numeroOffre=163035022W"},{"#uriOffre":"offre?numeroOffre=163035020W"}]}"
Im trying to make an application that do a login via CURL, but i cant make this application to work, with the cookie saved after the login. Aparently i can save the cookie, but can use it. I dont know if im doing wrong in the login code or the way to use the cookie saved. This application already work if i get the cookie manually via Chrome after login. I think it generate a primary cookie after the login at this page: https://www.comprasnet.gov.br/seguro/loginPortalFornecedor.asp, that redirects to this one https://www.comprasnet.gov.br/intro.htm, generating the first cookie. After i hit the menu to this page: https://www.comprasnet.gov.br/pregao/fornec/Acompanhar.asp, it generates the two cookies needed to work.
Code i made to try to do the login:
<?php
$cookieold = __DIR__.DIRECTORY_SEPARATOR.'cookieJar.txt';
$cookieactive = __DIR__.DIRECTORY_SEPARATOR.'cookieactive.txt';
$ch = curl_init();
$url = "https://www.comprasnet.gov.br/seguro/loginPortalFornecedor.asp";
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0');
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "perfil=Fornecedor&txtLogin=seulogin&txtSenha=suasenha&ambiente=Produção");
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieold);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$output = curl_exec($ch);
// Define uma nova URL para ser chamada (após o login)
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0');
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieold);
curl_setopt($ch, CURLOPT_URL, 'https://www.comprasnet.gov.br/intro.htm');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
// Executa a segunda requisição
$content = curl_exec ($ch);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0');
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieold);
curl_setopt($ch, CURLOPT_URL, 'https://www.comprasnet.gov.br/pregao/fornec/Acompanhar.asp');
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieactive);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
// Executa a terceira requisição
$content2 = curl_exec ($ch);
if ($output === FALSE) { // verifica erros no curl
echo "cURL Error: " . curl_error($ch);
}
curl_close($ch);
//echo $content2;
?>
Code that i already use with the cookie a get manually:
// iniciar sessao
$ch = curl_init();
// opcoes
curl_setopt($ch, CURLOPT_URL, "https://www.comprasnet.gov.br/pregao/fornec/Acompanhar.asp");
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0');
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIE, 'ASPSESSIONIDQGAADDTC=DDLGMJABKGCABIKENDGOBLJJ;ASPSESSIONIDQGCADASC=LFFGLJABPEAKKIOLNLLCOFIC');
//executar sessao
$output = curl_exec($ch);
if ($output === FALSE) { // verifica erros no curl
echo "cURL Error: " . curl_error($ch);
}
$output = strtr($output, $conversao); // função de conversão acentuado/não acentuado
//fechar sessao
curl_close($ch);
Any help will be aprecciate. Im not a programmer, just a curious guy trying to make my job easier. This application im making id for personnal use only.
my suggestion is to curl_close / curl_init after each output line. You are carrying over settings from the previous curl session like curl_setopt($ch, CURLOPT_COOKIESESSION, true) and CURLOPT_POSTFIELDS
so
$output = curl_exec($ch);
curl_close($ch);
$ch = curl_init();
$content = curl_exec($ch);
curl_close($ch);
$ch = curl_init();
I am trying to get an url by this code:
<?
$url='http://www.lacapital.com.ar/secciones/laciudad.html';
$userAgent = 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0';
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
$result = curl_exec($ch);
curl_close($ch);
?>
But $result give me this:
‹í}Ëw¹ÑïZú+0ÌwL*æ[oÉÒ\Š¢m%²¤+J“L||tÀnl»ÙàôC–<ñq·w—e³øNvÙÜs>ýc·ªôƒ‰¢%&‰“±ÙÝ#¡P¨*üPx½únÿ¸yöãI‹õÃËNÎ÷š,WªTþ´Ü¬TöÏöÙŸßž½;dµr•ùܜБw+•ÖQŽåúa8ܪT>þ\þ¼\–~¯rvZ¹BZ5̬–ÂTβڹÝÅWTàÕÀõ‚ dj›››*7¥Ü†B'tÅî!gM'²¹ÍþÊð7:!w™-Ø©¸ïHx$CÇrxPdÜ
î:˜üš…ÒæÌåÌñºÒpËy!¹…bÛKg¿Æ$¾è%__UTÑ‹¯"äÙ-‰Ÿ"çr'×”^(¼°tv=9f©§(®Â
²¿Í¬>÷½.mäXå6*‡ÜëE¼—¦$‚RãtJ6_t}ôS©×ªÕTZ^ûN¯æât/,x¹ÍêÕZí;Tí”,ÛeÖ(³3iË€¹ðŸ-|aõá”&üKïˬ-ØPø'(¯(t\çKF¤¡DZ’
¹mA-„ĸ¾pT+ÂÉâJfAùž-‘b7NEy¬:¶,ߢ6%Ï?p‹çGKý$®?KßR²†<–X‘ùšRÑ&aYÀ=ÈÛEî÷
µãñ"óbÇÙ)2ËåÓu,”n‘ ÛI3ë† { ñ"Ò² d9â²(/3´FkSÄúYd4#9°„§˜”CÇK§J×4
pÊérìŠ ( Þr>sV.DÐV“jà ÎÂGÁ#‡‘ϱB‘•°#g û
ú(|V¾àêS„ʼnMè;¼p7²‹xRtm(¹a#Ô Û’À
/…åx(»P8*íXý,Ð=õÅV(}$$<+N°U”„¸'Q±i;ðÙCYC{pE#¸ë
Ë“®ì¥%â…¾Ýp¶J0¦ºoŽß¶öŽÏRZttÜ8m¾=ø¡UdGÇÇû'c™ÞµFs#2L3²±,íÃóÓ“THûãþÁ)£"NöSySY‡¾„j‡×;9ÙÛ"—2¯_Áé¢ ²‰¼e]ígѾEä¦%|7•:ÕÕ¸\›ot¨ÌýÊ4a
ù”lŠÎ!of2ç&guYo~[ñÁuš[H;¯àÛ°¸¼¬|
$óEtVF¾ß‰tP” 3C¯7±ÝηŽ—ö_µ*ü©®®®UkµÍ•b¾²\[]ߨkÕµõµÍõêF±V[¯®UW
ÕTÂÃá…c§¯ÔêµÕj}µ^[Y¯ÖkÓÄšqäêÉÙäâCì¾ÀO¥XçQ(§ñëJ‹»Ù®ùâ°q{ê-îB)GòµÚ”oñ•ëxŸ€aw'GíyøVŽõ¡cB]IxúÒAṉ°Q•.¿Äç2ü5šÚÞ¥PFV¿”É3úJ›-«¸´:¬T½n*g„àþX[¹Z[¹›j
úMÎPT4p¾À›«ëW«ë÷,òÌYÞzýj½~Ïò(ÏœåÕj+Wðß=KÔ¹æ-sr¯Ü»L•K—¹øê»R‰5Ûm¶ÇÁJ¥¬r†×
ë}!ÂÃ>#£l+§Fý3pêº1÷4 S „e7*ITtç½Óeð
¼Uºèü’«·Àü%÷™;¬ãŽ¸Ü˜ø/plø;²pY܃E›Cõ\ÁqÇ
Š]§ù¢Ø•œEG;øOÏ—Ñ°8àþ§"
¼þ¯¿,Ê(FaüM*8²Ð‹§/¡<™[*C× ùb~i{\&+
ƒÎNu›9¯DÙ^/ìÃï—/—ØÏ‹¶´"„’eËà¬Z®À§‚xï|€ì__UT=Q&ï…g;ÝØ:ªÁþð'vâòkqÔb·Ê‰ƒK´£¶\_ÞX_[†^¢¶9ÚbÜ'oì„Öe§ôRmöþÿyHE—?¹Ý4—ÀI"]Öýkăv¯ü#¿*÷¤ì¹ô’
¡w×é€F|îÊÎGo¥^®'OXÚ4EH˜P\´J Ïs¼Þ8÷UR¨°jj÷áá
ÕGðÖ§QF¦éså÷Úº¹ß8k¼g¿¯~_ôøO
âôÏ_ÿÊÞØ^Äßåaôïó0ÎmX–Œ¼0_dùóFiy}¹¶¹±YªåQFÓîËw¼##V˜|¬—£<ð'“-Ä:œ#wvéˆÏ*E¡ydTeä³ÇË):W5³€de¬=¤ÍÔ?OypíYð5ô#±½/
ÑÐÂó¨;ÁVží¤JÁ™(ƒY†Ò’.ûžé„•Jžm©ü½Ä^²<Œ- Ü+Û2êÀhÆYŸÊž+¶
›ß¦jéZôD¨«ì]ŸñŠ-©Ìûê‡m”a¬
Ž¤-ÊöŒì °}QèÁˆ%#K^Àßд>ìb£Ž(Êbà_n±hÃÙRP[^=!ýiKÁÏjÞ¦ÖdPʶȮ#}‡nHO¹.2ö3(sD#‚ÒJm3Ÿq43å€I„ˆ
ËØY€¯ð¨4øgÄ)ÜË3-ƒOª/¯.oÎa¦=~Д‚Ñ]\ÖFøʪÈÖâ«Ž´¯)\áBD±¶KæØÀ-ÿ$ä¥ð/ྯÀ¿Úͽæ–èHù‰µ÷ÿ¨šÈdêvJ>ô)X¦J®KNƵ€¼†ÃêÜGxî~$Í›¬r餆Ž±N³w}€Ôt×0<÷0&”µ#PDøPvløæØ™6\„ëyèb»ºZdµ+нƒwÕíÜÚÀ%öÎèhéA¦š‚®
CÁxmHðË\úö§üÒÒö¨;=ûì„г?ÄÚ“6ÝïRâ Š ‘Ÿ´h¡àÛåºàtßM+PY
ìcÒ¤ Ï”&ýVºœF¨8&»øìØ#=#eÄÔwÈJ‰jákZZ9m2Åœ¦[úÄ Ù¨ qÄ°zÁ¤
ƒ7'›p¾§œ©BÁÅ4äç¯Û‹ $ð1ê»à7ìÆ¿ýÁ|Js§KZ,cŸÏ–ŸËÝÎ)àhlÓ
¤¾4°8€:ÁÇLÄàO¥BÕea_°×{ìm´Oúòz¯Œ_
*c¤Çê'¸Â}Jáì³®/DŸ÷Öt$÷mML§Ð#¸ç¾‹„pà8ô¦¯9µ½NQÆд¢ÜToØkâÄ«’MÝ2FÖ‘ç¨^M—½VhVQDÃêëñ#LÈ©SEChc¬é÷:·VåˆÑÜà¿
€R$€á>k—ŸÙ5øT†Qgh|iƒ
¨,Ç'¯ÀRÄ© †|g~½÷î…¼0)ì;|è •õ+ê·i²†m뉊QeµÀ:Xc
ÆÆ!à¨Ö%˜;,ñ΀õ$°Þ¾X4
M)ÊAÔAÍêˆBŽØÝDʵÞÄ£>èXa\•2HIÆ•´ËÝ# ]W*5øû¿
9lx†‚[ý,XZXXÀÿÐÈ2‘´À©üW…´¤Ca œðþê#
à™ÉÜ™”yRâÌ7(ó%d…O_6Öøfu¦“þ±ïv˜¹®®6}£„hÒÓb9ìiµo.PyIÂ'2]f|çWJ©¿ÆúocBÖCÉmÒ70ß|ÀTÏÈôû¾ôd¸×*åß
%W6o‹NÔc ¶¨¤4®#Pe8ÿR¸×ðþ‘Ca3îÙl€4LÑÁ#íFJX
hC‹0D#"ÑBO©³ÀtÝ”¦†–‹,Ñc(¥[†#Ì.i‡duУÝa èNG#ªÈMÇ ?k
ä>,¤àz
3àï,:×îÂÞÅy»Ba‚—À5Ñ÷š~åÀqärˆÎsªs$šPÝ[±|'…ai8Qù=Qü}EÙãÒÒÄÞÇÕÓ};9DmC§éŸSaèîK+54ØfúõáaâèU»†-ܽ²(ÅCGE~[gjø=êW™sðz«V~ØŠ‡Æv0’©’+^Â÷•\18ØʉÎúFƒ[959+Šƒë½~ºØ\^V%èçÚFõjzñ–âÉëåjõª¾ZmŒ½Ù{ÓLÞ¬Á›Zµšû€–jTëÓD[i‡Ü•‡#õ3ƒ(ø®Üž‰Ö¤¿
/ÀÔNËëÂ’v’JQµª¡Ç
dõ‰R#(ha’OQ„Ô‹²¡hRq0&€.†MN³æ«=d“>7ìv_~.à´U&Ûûàƒ*pšùK³œ®Ì6y{øšâ_óyxh{Òƒà§ïbFpˆ2’Fé]»®~ØVfÐM¹úb9øÅÛ±ÅÕq·k¶[§?´NwrK¦$H^¾TÓ"€Ç—;¬VÕD–B~;óu‰¨1Êm’ê5Q»®Þa?>ÓëAi_(÷oÔáàõ-Qƒƒ×§w<倔ÚÏäyGFáVläS~I(•‘®8]Cê5Î~Ф‡}ÌáC_Ož(æ©ä«Ã«|úµNªÞ¶è‹íÛÉ{0Ö†<™F,Þ´Ðì;®]€vÕZ½”#q.f……Ãx8ÿ2o_Ãsò‹òç5QË•PÝ·‰”¨÷ÙVk7ONΰó0=C…Áã{øo%¸ý|…B‰c+ÔTFWhLpA¬¸ß´ÄʼʔŸ ÎVô¬ÊJe}ƒoæ•Of$ˆµØtÆM4ŒáGdÖu¶EØ°ßNìѯ¼ŽýçH®¥Øs˜dìV…G¼ú€¸oqÔÕAú6Ž1
I've tried you code and yes it is garbled. One this to point out is, you can also add an option CURLOPT_ENCODING in curl. Example:
$url = 'http://www.lacapital.com.ar/secciones/laciudad.html';
$userAgent = 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0';
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_ENCODING, ''); // add this one
$result = curl_exec($ch);
curl_close($ch);
echo $result;
Note: As #Akshay suggested, this also works well.
curl_setopt($ch, CURLOPT_ENCODING, 'gzip'); // add this one