Oxylabs Amazon Scraper

repository·main·Indexed 25 days ago

https://github.com/oxylabs/amazon-scraper

A tool for extracting Amazon product data via a free Python CLI or a professional-grade Oxylabs API. The CLI tool allows for department-level scraping into CSV files, while the API supports structured data extraction for best sellers, pricing, product pages, Q&A, search results, and seller information using specific sources like amazon_product and amazon_pricing.

Tokens
3.6K
Snippets
8
Records
21
Agent score
85%

What's inside amazon-scraper

  1. Scrape Amazon Sellers data using Oxylabs API

    main

    Use the amazon_sellers data source to retrieve information from Amazon Seller pages. You must provide a 13-character seller ID in the query parameter. To receive structured data, set the parse parameter to true (note: structured parsing is currently only supported for the desktop user_agent_type).

    import requests
    from pprint import pprint
    
    # Structure payload.
    payload = {
        'source': 'amazon_sellers',
        'domain': 'de',
        'query': 'ABNP0A7Y0QWBN',
        'parse': True
    }
    
    # Get response.
    response = requests.request(
        'POST',
        'https://realtime.oxylabs.io/v1/queries',
        auth=('user', 'pass1'),
        json=payload,
    )
    
    # Print prettified response to stdout.
    pprint(response.json())
  2. Scrape Amazon product data using the CLI

    main

    You can scrape product data from a specific Amazon department page using the scrape command. You must provide the department URL as a parameter and ensure the URL is enclosed in quotation marks to prevent parsing errors.

    Command Syntax:

    make scrape URL="<amazon_department_page_url>"

    Example:

    make scrape URL="https://www.amazon.com/s?i=specialty-aps&bbn=16225009011&rh=n%3A%2116225009011%2Cn%3A541966&ref=nav_em__nav_desktop_sa_intl_computers_and_accessories_0_2_5_6"
  3. Install the Free Amazon Scraper

    main

    To use the free Amazon Scraper tool, ensure you have Python 3.11 installed on your system. Navigate to the repository directory in your terminal and run the following command to install dependencies:

    make install
  4. Make a request to the Oxylabs Scraper API using Python

    main

    Use the requests library to send a POST request to the Oxylabs API. You must provide your credentials via HTTP Basic Auth and include a JSON payload containing the source, url, and parse parameters.

    import requests
    from pprint import pprint
    
    # Structure payload.
    payload = {
        'source': 'amazon',
        'url': 'https://www.amazon.co.uk/dp/B0BDJ279KF',
        'parse': True
    }
    
    # Get response.
    response = requests.request(
        'POST',
        'https://realtime.oxylabs.io/v1/queries',
        auth=('YOUR_USERNAME', 'YOUR_PASSWORD'), #Your credentials go here
        json=payload,
    )
  5. Scrape Amazon product offer listings with `amazon_pricing`

    main

    Use the amazon_pricing data source to retrieve Amazon product offer listings. You must provide a 10-symbol ASIN code in the query parameter. Setting parse to true will return structured data.

    import requests
    from pprint import pprint
    
    # Structure payload.
    payload = {
        'source': 'amazon_pricing',
        'domain': 'nl',
        'query': 'B09RX4KS1G',
        'parse': True,
    }
    
    # Get response.
    response = requests.request(
        'POST',
        'https://realtime.oxylabs.io/v1/queries',
        auth=('user', 'pass1'),
        json=payload,
    )
    
    # Print prettified response to stdout.
    pprint(response.json())
  6. Scrape Amazon Questions & Answers with `amazon_questions`

    main

    Use the amazon_questions data source to retrieve a specific product's Questions & Answers pages. You must provide a 10-symbol ASIN code in the query parameter. Setting parse to true will return structured data.

    import requests
    from pprint import pprint
    
    # Structure payload.
    payload = {
        'source': 'amazon_questions',
        'domain': 'nl',
        'query': 'B09RX4KS1G',
        'parse': True,
    }
    
    # Get response.
    response = requests.request(
        'POST',
        'https://realtime.oxylabs.io/v1/queries',
        auth=('user', 'pass1'),
        json=payload,
    )
    
    # Print prettified response to stdout.
    pprint(response.json())
  7. Scrape Amazon Best Sellers with `amazon_bestsellers`

    main

    Use the amazon_bestsellers data source to retrieve Amazon Best Sellers pages. The query parameter expects a Department name (e.g., Clothing, Shoes & Jewelry). You can also use the context parameter with category_id to search for items in a specific browse node.

    import requests
    from pprint import pprint
    
    # Structure payload.
    payload = {
        'source': 'amazon_bestsellers',
        'domain': 'de',
        'query': 'automotive',
        'start_page': 2,
        'parse': True,
        'context': [
            {'key': 'category_id', 'value': 82400031},
        ],
    }
    
    # Get response.
    response = requests.request(
        'POST',
        'https://realtime.oxylabs.io/v1/queries',
        auth=('user', 'pass1'),
        json=payload,
    )
  8. Scrape Amazon product pages using `amazon_product` source

    main

    Use the amazon_product source to retrieve specific Amazon product pages using an ASIN. You must provide the 10-symbol ASIN code in the query parameter and set the source to amazon_product.

    Query Parameters

    ParameterDescriptionDefault Value
    sourceData source (required)amazon_product
    query10-symbol ASIN code (required)-
    domainDomain localization (e.g., com, nl)com
    geo_locationThe Deliver to location-
    user_agent_typeDevice type and browserdesktop
    renderEnables JavaScript rendering-
    callback_urlURL to your callback endpoint-
    parseSet to true to return structured data-
    context:<br>autoselect_variantSet to true to append th=1&psc=1 to the URL for accurate pricing/buybox data. Set to false or omit to see the parent ASIN page.false
    import requests
    from pprint import pprint
    
    # Structure payload.
    payload = {
        'source': 'amazon_product',
        'domain': 'nl',
        'query': 'B09RX4KS1G',
        'parse': True,
        'context': [
        {
          'key': 'autoselect_variant', 'value': True
        }],
    }
    
    # Get response.
    response = requests.request(
        'POST',
        'https://realtime.oxylabs.io/v1/queries',
        auth=('user', 'pass1'),
        json=payload,
    )
    
    pprint(response.json())
  9. Understand the output format of the Free Amazon Scraper

    main

    After running the scraper, the tool generates a file named amazon_products.csv in your current directory. The CSV contains the following columns:

    • title: The title of the product.
    • url: The URL pointing to the product's Amazon page.
    • asin_code: The product's unique ASIN code.
    • image_url: The URL of the product image.
    • price: The price of the product (this field may be empty if the product is out of stock).
  10. Configure the Oxylabs Amazon Scraper API

    main

    For large-scale scraping, use the Oxylabs Web Scraper API. The amazon source allows you to submit any Amazon URL to retrieve content.

    Supported Amazon Data Sources

    SourceDescriptionStructured data
    amazonSubmit any Amazon URL you like.Depends on the URL.
    amazon_bestsellersList of best seller items in a taxonomy node.Yes
    amazon_pricingList of offers available for an ASIN.Yes
    amazon_productProduct page of an ASIN.Yes
    amazon_questionsQ&A page of an ASIN.Yes
    amazon_searchSearch results for a search term.Yes
    amazon_sellersSeller information of a seller.Yes

    Query Parameters for amazon source

    ParameterDescriptionDefault Value
    sourceRequired. Data source.amazon
    urlRequired. Direct URL (link) to Amazon page.-
    user_agent_typeDevice type and browser.desktop
    renderEnables JavaScript rendering.-
    callback_urlURL to your callback endpoint.-
    parseIf true, returns structured data for supported page types.false
  11. Query parameters for `amazon_pricing`

    main

    The following parameters are available for the amazon_pricing data source:

    ParameterDescriptionDefault Value
    sourceData source (Required)amazon_pricing
    query10-symbol ASIN code (Required)-
    domainDomain localization for Amazoncom
    start_pageStarting page number1
    pagesNumber of pages to retrieve1
    geo_locationThe Deliver to location-
    user_agent_typeDevice type and browserdesktop
    renderEnables JavaScript rendering
    callback_urlURL to your callback endpoint-
    parsetrue will return structured data-
  12. Query parameters for `amazon_bestsellers`

    main

    The following parameters are available for the amazon_bestsellers data source:

    ParameterDescriptionDefault Value
    sourceData source (Required)amazon_bestsellers
    domainDomain localization for Amazoncom
    queryDepartment name. Example: Clothing, Shoes & Jewelry-
    start_pageStarting page number1
    pagesNumber of pages to retrieve1
    geo_locationThe Deliver to location-
    user_agent_typeDevice type and browserdesktop
    renderEnables JavaScript rendering
    callback_urlURL to your callback endpoint-
    parsetrue will return structured data-
    context (category_id)Search for items in a particular browse node (product category)-