简体   繁体   English

亚马逊:是否可以在URL中为亚马逊搜索结果指定邮政编码?

[英]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. 如果我将带有搜索结果的Ama​​zon URL复制并且有人打开另一个IP,则结果可能会有所不同。 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 例如: 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. 如果您从Dallas IP中打开此URL,您将获得102页的结果。

If you open it with Honolulu IP you'll get 101 pages. 如果使用檀香山IP打开它,您将获得101页。

If you open it from Russian IP you'll get 93 pages. 如果您从俄语IP中打开它,则会得到93页。

Is that possible to specify US ZIP code for shipping right in the url so that it displays same results for every IP address? 是否可以在网址中指定要发送的美国邮政编码,以使每个IP地址显示相同的结果?

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? 也许有人知道如何使用url参数将设计锁定到一种布局? :) :)

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. 这个想法是:您必须发送与在浏览器中手动更改ZIP时发送的请求相同的请求。 Then your ZIP code will be remembered for you session. 然后,您的会话将被记住。

Here is my solution in PHP using GuzzleHttp Client: 这是我使用GuzzleHttp Client在PHP中提供的解决方案:

$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. 我使用真棒狂饮功能- cookies容器: http://docs.guzzlephp.org/en/stable/request-options.html#cookies它可以记住并就像浏览器会做请求之间的过程饼干。

In all further requests you should keep using these cookies and it will return you results for your ZIP. 在所有其他请求中,您应继续使用这些cookie,它将返回您ZIP的结果。

Of course you can process cookies manually, Guzzle isn't required but makes things simpler. 当然,您可以手动处理Cookie,Guzzle不是必需的,但是使事情变得更简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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