How can I solve the problem of collecting ebay garbled codes with curl? Dear friends, I have used curl to collect information and found that the information collected from ebay stores is always garbled, for example, $ urlstores. ebay. comsportingamerica; $ caijicurl_get_contents ($ url); print_r ($ caiji); can anyone explain this? Thank you! Function & ask curl How to collect ebay garbled code?
Dear friends, I have used curl to collect information and found that the information collected from ebay stores is always garbled, for example:
$ Url = "http://stores.ebay.com/sportingamerica ";
$ Caiji = curl_get_contents ($ url );
Print_r ($ caiji );
Can anyone explain this? Thank you!
Function curl_get_contents ($ url)
{
$ Ch = curl_init ();
Curl_setopt ($ ch, CURLOPT_URL, $ url );
// Curl_setopt ($ ch, CURLOPT_HEADER, 1 );
Curl_setopt ($ ch, CURLOPT_TIMEOUT, 5 );
Curl_setopt ($ ch, CURLOPT_USERAGENT, _ USERAGENT _);
Curl_setopt ($ ch, CURLOPT_REFERER, _ REFERER _);
Curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 1 );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
$ R = curl_exec ($ ch );
Curl_close ($ ch );
Return $ r;
}
There should be no problem with Encoding. My php file is encoded in UTF-8 and the ebay page is encoded in UTF-8.
------ Solution ----------------------
The data is compressed by gzip.
Set this curl_setopt ($ ch, CURLOPT_ENCODING, 1 );
Or echo gzdecode ($ caiji) after reading back );
------ Solution ----------------------
You can set the returned code encoding format to text/utf8.