简体   繁体   中英

Amazon: is it possible to specify zip code in the URL for Amazon search results?

I have noticed an issue. If I copy Amazon URL with search results and somebody with another IP opens it then the results can be different. For example: https://www.amazon.com/s/ref=sr_nr_p_36_0?lo=toys-and-games&rh=n%3A165793011%2Cp_72%3A1248964011&sort=price-desc-rank&low-price=34.99&high-price=34.99

If you open this URL in from Dallas IP you'll get 102 pages with results.

If you open it with Honolulu IP you'll get 101 pages.

If you open it from Russian IP you'll get 93 pages.

Is that possible to specify US ZIP code for shipping right in the url so that it displays same results for every IP address?

Another little issue I have noticed - it displays different page layout for different people. Sometimes it's default blue links, sometimes it has silver buttons. Maybe somebody knows how to lock the design to one layout with url parameters? :)

There is no simple solution, so here is my complicated way.

The idea is: you must send the same request which is get sent when you manually change ZIP in your browser. Then your ZIP code will be remembered for you session.

Here is my solution in PHP using GuzzleHttp Client:

$jar = new \GuzzleHttp\Cookie\CookieJar();
$client = new \GuzzleHttp\Client([
    'headers' => [
        'accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
        'accept-language' => 'en;q=0.8',
        'user-agent' => '', //set some User-Agent or just leave it empty cos it works too
        'x-requested-with' => 'XMLHttpRequest'
    ],
    'cookies' => $jar,
]);

try {
    $client->post('https://www.amazon.com/gp/delivery/ajax/address-change.html', [
        'form_params' => [
            'locationType' => 'LOCATION_INPUT',
            'zipCode' => '11219', //YOUR ZIP HERE
            'storeContext' => 'office-products',
            'deviceType' => 'web',
            'pageType' => 'Detail',
            'actionSource' => 'glow',
        ]
    ]);
} catch (RequestException $e) {
    echo "Failed to set ZIP";
}

$response = $client->get('...'); //get any other page from Amazon, now it will have proper ZIP

I'm using awesome Guzzle feature - cookies container: http://docs.guzzlephp.org/en/stable/request-options.html#cookies It can remember and process cookies between requests just like browser would do.

In all further requests you should keep using these cookies and it will return you results for your ZIP.

Of course you can process cookies manually, Guzzle isn't required but makes things simpler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM