Created
August 7, 2017 03:00
-
-
Save wjfz/5cadc2a58abc356e54c657167754765e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private function doFetch() | |
{ | |
$header[] = "Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"; | |
$header[] = "Accept-Language:zh-CN,zh;q=0.8,zh-TW;q=0.6,en;q=0.4"; | |
$header[] = "Cache-Control:max-age=0"; | |
$header[] = "Connection:keep-alive"; | |
$header[] = "DNT:1"; | |
$header[] = "Host:www.amazon.cn"; | |
$header[] = "Upgrade-Insecure-Requests:1"; | |
$ch = curl_init(); | |
$options = array( | |
CURLOPT_URL => "https://www.amazon.cn/gp/aw/d/B072FHCH3L/", | |
CURLOPT_TIMEOUT => 10, | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_SSL_VERIFYPEER => false, | |
CURLOPT_SSL_VERIFYHOST => false, | |
CURLOPT_AUTOREFERER => false, | |
CURLOPT_FOLLOWLOCATION => false, | |
CURLOPT_HEADER => false, | |
CURLOPT_COOKIE => 'x-wl-uid=1XEGm8EWBn5UKcY+jAP0ADhWddOnj1Ts7fNDWxFYzeENnr/h8IH3ES4EM6x3kW3XKc0z5cDhtf6g=; csm-hit=s-FY08R8EZB54KT8J5HPGM|1501839230230; session-token=kRhR651r1zNpJkpljpNx6E1jPuuxzI1nPNJ/oQ9P10n/f0VkjO/fCUct5YMM456P80uys5aHJnxDmgBbL+/mHL+xLoPSx329j8K0Z6LDs+JduMOaF3GjeJ21uCQY/iQDLnDpE0FupUXLxfLTlOD1aWQYBp+c9Pn0sW2w9Uj+fi27G9LL1i//5ZFdIAX/oFAQdkGFkTuLxKJE/fI/2QwMGRzq4qpddHscR1YvhkcuxBbI3ZQYDjvNwQ==; ubid-acbcn=460-1002305-3265660; session-id-time=2082729601l; session-id=462-6528075-1036645', | |
CURLOPT_ENCODING => 'gzip, deflate, br', | |
CURLOPT_USERAGENT => 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1', | |
CURLOPT_HTTPHEADER => $header | |
); | |
curl_setopt_array($ch, $options); | |
$result = curl_exec($ch); | |
curl_close($ch); | |
// preg_match_all("/\/gp\/aw\/d\/(.*)\/ref=/U", $result, $matches); | |
preg_match_all("|/gp/aw/d/(.*)/|U", $result, $matches); | |
preg_match("|<span id=\"priceblock_ourprice\" class=\"a-size-medium a-color-price\">¥(.*) | |
</span>|U", $result, $matches2); | |
preg_match("|<span class=\"a-size-small a-color-price a-text-bold\"> | |
¥(.*) | |
</span>|U", $result, $matches3); | |
$matches[1] = array_unique($matches[1]); | |
var_dump($matches); | |
var_dump($matches2); | |
var_dump($matches3); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment