簡體   English   中英

亞馬遜:是否可以在URL中為亞馬遜搜索結果指定郵政編碼?

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

我注意到了一個問題。 如果我將帶有搜索結果的Ama​​zon URL復制並且有人打開另一個IP,則結果可能會有所不同。 例如: 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

如果您從Dallas IP中打開此URL,您將獲得102頁的結果。

如果使用檀香山IP打開它,您將獲得101頁。

如果您從俄語IP中打開它,則會得到93頁。

是否可以在網址中指定要發送的美國郵政編碼,以使每個IP地址顯示相同的結果?

我注意到的另一個小問題-它為不同的人顯示不同的頁面布局。 有時是默認的藍色鏈接,有時有銀色按鈕。 也許有人知道如何使用url參數將設計鎖定到一種布局? :)

沒有簡單的解決方案,所以這是我的復雜方法。

這個想法是:您必須發送與在瀏覽器中手動更改ZIP時發送的請求相同的請求。 然后,您的會話將被記住。

這是我使用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

我使用真棒狂飲功能- cookies容器: http://docs.guzzlephp.org/en/stable/request-options.html#cookies它可以記住並就像瀏覽器會做請求之間的過程餅干。

在所有其他請求中,您應繼續使用這些cookie,它將返回您ZIP的結果。

當然,您可以手動處理Cookie,Guzzle不是必需的,但是使事情變得更簡單。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM