GithubHelp home page GithubHelp logo

anupkumarpanwar / amazondata Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 1.0 41 KB

A python package to get amazon product and search data in json form. The package does not require any API keys as it works by scraping the amazon page.

Home Page: https://pypi.org/project/amazondata/

License: MIT License

Python 100.00%
amazon scraping

amazondata's Introduction

amazondata

PyPI version

A python package to get amazon product and search data in json form. The package does not require any API keys as it works by scraping the amazon page.

Reference: How To Scrape Amazon Product Details and Pricing using Python

Install

pip install amazondata

Usage

To get Amazon product details from the url, use the following function.

get_product_from_url(url)

from amazondata.product_details_extractor import ProductDetailsExtractor

product_details_extractor = ProductDetailsExtractor()

data = product_details_extractor.get_product_from_url('https://www.amazon.in/dp/B09JSYVNZ2')

print(data)

To get Amazon product details from the ASIN (Amazon Standard Identification Number) code, use the following function.

get_product_from_asin_code(asin_code)

from amazondata.product_details_extractor import ProductDetailsExtractor

product_details_extractor = ProductDetailsExtractor()

data = product_details_extractor.get_product_from_asin_code('B09JSYVNZ2')

print(data)

To get the list of products from search query use the following function

search(query, page)

from amazondata.search_result_extractor import SearchResultExtractor

search_result_extractor = SearchResultExtractor()

data = search_result_extractor.search('perfume for men', 3)

print(data)

NOTE: Optionally, you can pass custom headers to all these functions. The default headers value is:

headers = {
            "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
            "Sec-Fetch-Site": "none",
            "Host": "www.amazon.in",
            "Accept-Language": "en-IN,en-GB;q=0.9,en;q=0.8",
            "Sec-Fetch-Mode": "navigate",
            "Accept-Encoding": "gzip, deflate, br",
            "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15",
            "Connection": "keep-alive",
            "Upgrade-Insecure-Requests": "1",
            "Sec-Fetch-Dest": "document",
            "Priority": "u=0, i",
        }

In case the the scraper gets blocked from Amazon, you can fetch the html code using selenium and pass the html code to the following function

data = search_result_extractor.extract_search_results(html_code)
data = product_details_extractor.extract_product_details(html_code)

amazondata's People

Contributors

anupkumarpanwar avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ofrasergreen

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.