Automate Amazon with Datakund
Introduction
bot-studio
is an automation library which can be used to automate tasks like sending mails,scraping data,auto checkout and many more. You can download the source code from here(see here)
It uses selenium to automate the things. You can use its inbuilt functions like amazon_login
, amazon_search
etc. in a very easy way.
Installation/Usage:
You can find this package on Pypi (see here).
Command to install :- pip install bot-studio
Import bot-studio
from bot_studio import *
Creating Object
amazon=bot_studio.amazon()
or
amazon=bot_studio.amazon(headless=True,...)
It will return the object which you can further use to call amazon functions and opens an automated browser
Browser Options
Option |
Default Value |
Description |
---|---|---|
headless |
False |
Can set it to True if wants headless |
proxy |
No proxy |
Pass proxy value e.g 98.0.2.5:4000 |
profile_path |
creates temporary profile |
Pass profile path e.g C:\Users\username\AppData\Local\Google\Chrome\User Data\ |
user_agent |
No user agent |
Pass user agent e.g python 2.7”, “platform”:”Windows |
download_folder |
Downloads in default folder |
If want to set download directory to custom e.g E:files\ |
Functions
bot-studio
provides following functions for amazon:-
Login
It logins to the amazon through credentials passed in email
and password
. By default it logins to amazon.com, but you can login to others by passing login url in login_url
.
body: returns data
success_score: api success rate
errors: errors encountered in api
Here is the code:-
- amazon.login(email='datakund@gmail.com', login_url='https://www.amazon.com/gp/sign-in.html', password='pwd123')
- Parameters
email (str) – amazon email
login_url (str) – amazon login url(can exclude it)
password (str) – amazon password
- Returns
{“body”: {}, “success_score”: “100”, “errors”: []}
- Return type
dict
Logout
It goes to homepage and then log out from amazon. By default log outs from amazon.com, can send other url in home_url
.
body: returns data
success_score: api success rate
errors: errors encountered in api
Here is the code:-
- amazon.logout(home_url='https://www.amazon.in/')
- Parameters
home_url (str) – Home Url
- Returns
{“body”: {}, “success_score”: “100”, “errors”: []}
- Return type
dict
Search
It searches the keyword passed in keyword
.
body: returns data
success_score: api success rate
errors: errors encountered in api
Here is the code:-
- amazon.search(keyword='shoes')
- Parameters
keyword (str) – keyword which needs to be searched on amazon
- Returns
{“body”: {}, “success_score”: “100”, “errors”: []}
- Return type
dict
Select Brand
It selects the brand passed in brand
when search is made.
body: returns data
success_score: api success rate
errors: errors encountered in api
Here is the code:-
- amazon.select_brand(brand='Adidas')
- Parameters
brand (str) – Brand name like Nike if you searched shoes
- Returns
{“body”: {}, “success_score”: “100”, “errors”: []}
- Return type
dict
Select Category
It selects the category passed in category
when search is made.
body: returns data
success_score: api success rate
errors: errors encountered in api
Here is the code:-
- amazon.select_category(category='Clothes')
- Parameters
category (str) – Category name like shoes/clothes
- Returns
{“body”: {}, “success_score”: “100”, “errors”: []}
- Return type
dict
Get Reviews
It fetches the reviews data from reviews page opened in browser.
body: returns data
success_score: api success rate
errors: errors encountered in api
Here is the code:-
- amazon.get_reviews()
- Returns
{“body”: [{‘Stars’: ‘Stars’, ‘Review Link’: ‘Review Link’, ‘Review’: ‘Review’}], “success_score”: “100”, “errors”: []}
- Return type
dict
Add To Cart
It adds the product to cart passed in product_link
.
body: returns data
success_score: api success rate
errors: errors encountered in api
Here is the code:-
- amazon.add_to_cart(product_link='https://www.amazon.in/Sony-WF-XB700-Wireless-Bluetooth-Headphones/dp/B085VQFZ8Z/ref=sr_1_2_sspa?dchild=1&keywords=jbl+earbuds&pd_rd_r=9f5d38ab-dcc6-4c29-bef0-e646dffbc5a3&pd_rd_w=3Paz5&pd_rd_wg=F14yq&pf_rd_p=1abe8808-d6bc-4840-858b-6acddb119a7a&pf_rd_r=MST8X5YENPSB71RQ87KS&qid=1613454716&sr=8-2-spons&psc=1&spLa=ZW5jcnlwdGVkUXVhbGlmaWVyPUEyWU1LOVBNVFBWMzI4JmVuY3J5cHRlZElkPUEwNTA4Nzg1MlUzQkQ5SkhHQUZZSiZlbmNyeXB0ZWRBZElkPUEwODUzMjU4OTRZN1dRWDI0NVdZJndpZGdldE5hbWU9c3BfYXRmJmFjdGlvbj1jbGlja1JlZGlyZWN0JmRvTm90TG9nQ2xpY2s9dHJ1ZQ==')
- Parameters
product_link (str) – product link
- Returns
{“body”: {}, “success_score”: “100”, “errors”: []}
- Return type
dict
Search Results
It fetches the data of amazon search results.
body: returns data
success_score: api success rate
errors: errors encountered in api
Here is the code:-
- amazon.search_results()
- Returns
{“body”: [{‘Link’: ‘Link’, ‘Price’: ‘Price’, ‘Title’: ‘Title’}], “success_score”: “100”, “errors”: []}
- Return type
dict
Click Next
It clicks Next button on amazon search results page.
body: returns data
success_score: api success rate
errors: errors encountered in api
Here is the code:-
- amazon.click_next()
- Returns
{“body”: {}, “success_score”: “100”, “errors”: []}
- Return type
dict
Buy
It goes to product url passed in product_url
and clicks on buy button.
body: returns data
success_score: api success rate
errors: errors encountered in api
Here is the code:-
- amazon.buy(product_url='https://www.amazon.in/Sony-WF-XB700-Wireless-Bluetooth-Headphones/dp/B085VQFZ8Z/ref=sr_1_2_sspa?dchild=1&keywords=jbl+earbuds&pd_rd_r=9f5d38ab-dcc6-4c29-bef0-e646dffbc5a3&pd_rd_w=3Paz5&pd_rd_wg=F14yq&pf_rd_p=1abe8808-d6bc-4840-858b-6acddb119a7a&pf_rd_r=MST8X5YENPSB71RQ87KS&qid=1613454716&sr=8-2-spons&psc=1&spLa=ZW5jcnlwdGVkUXVhbGlmaWVyPUEyWU1LOVBNVFBWMzI4JmVuY3J5cHRlZElkPUEwNTA4Nzg1MlUzQkQ5SkhHQUZZSiZlbmNyeXB0ZWRBZElkPUEwODUzMjU4OTRZN1dRWDI0NVdZJndpZGdldE5hbWU9c3BfYXRmJmFjdGlvbj1jbGlja1JlZGlyZWN0JmRvTm90TG9nQ2xpY2s9dHJ1ZQ==')
- Parameters
product_url (str) – link of product
- Returns
{“body”: {}, “success_score”: “100”, “errors”: []}
- Return type
dict
Select Payment Method
It chooses the payment method passed in payment_method
.
body: returns data
success_score: api success rate
errors: errors encountered in api
Here is the code:-
- amazon.select_payment_method(payment_method='Net Banking')
- Parameters
payment_method (str) – payment method
- Returns
{“body”: {}, “success_score”: “100”, “errors”: []}
- Return type
dict
Select Bank
It chooses the bank passed in bank
.
body: returns data
success_score: api success rate
errors: errors encountered in api
Here is the code:-
- amazon.select_bank(bank='HDFC Bank')
- Parameters
bank (str) – bank name e.g. HDFC Bank
- Returns
{“body”: {}, “success_score”: “100”, “errors”: []}
- Return type
dict
Place Order
It places the order after payment method is choosen.
body: returns data
success_score: api success rate
errors: errors encountered in api
Here is the code:-
- amazon.place_order()
- Returns
{“body”: {}, “success_score”: “100”, “errors”: []}
- Return type
dict
Fill Cvv
It fills CVV passed in cvv
.
body: returns data
success_score: api success rate
errors: errors encountered in api
Here is the code:-
- amazon.fill_cvv(cvv='234')
- Parameters
cvv (str) – Debit/Credit card cvv
- Returns
{“body”: {}, “success_score”: “100”, “errors”: []}
- Return type
dict
Click Next Reviews
It clicks Next button on the reviews page opened in browser.
body: returns data
success_score: api success rate
errors: errors encountered in api
Here is the code:-
- amazon.click_next_reviews()
- Returns
{“body”: {}, “success_score”: “100”, “errors”: []}
- Return type
dict
Product Info
It fetches information of the product passed in product_url
.
body: returns data
success_score: api success rate
errors: errors encountered in api
Here is the code:-
- amazon.product_info(product_url='https://www.amazon.in/Sony-WF-XB700-Wireless-Bluetooth-Headphones/dp/B085VQFZ8Z/ref=sr_1_2_sspa?dchild=1&keywords=jbl+earbuds&pd_rd_r=9f5d38ab-dcc6-4c29-bef0-e646dffbc5a3&pd_rd_w=3Paz5&pd_rd_wg=F14yq&pf_rd_p=1abe8808-d6bc-4840-858b-6acddb119a7a&pf_rd_r=MST8X5YENPSB71RQ87KS&qid=1613454716&sr=8-2-spons&psc=1&spLa=ZW5jcnlwdGVkUXVhbGlmaWVyPUEyWU1LOVBNVFBWMzI4JmVuY3J5cHRlZElkPUEwNTA4Nzg1MlUzQkQ5SkhHQUZZSiZlbmNyeXB0ZWRBZElkPUEwODUzMjU4OTRZN1dRWDI0NVdZJndpZGdldE5hbWU9c3BfYXRmJmFjdGlvbj1jbGlja1JlZGlyZWN0JmRvTm90TG9nQ2xpY2s9dHJ1ZQ==')
- Parameters
product_url (str) – product url
- Returns
{“body”: {‘Review Terms’: ‘Review Terms’, ‘NoOfRatings’: ‘NoOfRatings’, ‘ReviewsLink’: ‘ReviewsLink’, ‘Price’: ‘Price’, ‘Ratings’: ‘Ratings’, ‘Description’: ‘Description’, ‘Features’: ‘Features’, ‘Offers’: ‘Offers’, ‘Title’: ‘Title’}, “success_score”: “100”, “errors”: []}
- Return type
dict
Other Functions
You can use basic functions which selenium provides with this library like opening a url, get pagesource, get current url etc. These are the functions:-
Open
It will open the url provided in the argument.
- amazon.open(url)
- Parameters
url (str) – Link which need to be opened
- Returns
{}
- Return type
dict
Get Page Title
It returns the title of page opened.
- amazon.get_page_title()
- Returns
{“pagetitle”:”amazon”}
- Return type
dict
Get Page Source
It returns the pagesource of page opened.
- amazon.get_page_source()
- Returns
{“pagesource”:”pagesource”}
- Return type
dict
Get Current Url
It returns the pagesource of page opened.
- amazon.get_current_url()
- Returns
{“url”:”url”}
- Return type
dict
Reload
It reloads the page opened.
- amazon.reload()
- Returns
{}
- Return type
dict
Keypress
It perform the keypress passed.
- amazon.keypress(key)
- Parameters
key (str) – Key which need to be pressed, e.g pagedown,arrowleft,enter
- Returns
{}
- Return type
dict
Scroll
It scrolls to the end of page.
- amazon.scroll()
- Returns
{}
- Return type
dict
End
It ends the amazon session and close the automated chromedriver.
Note
You will need to create amazon object again after end()
.
- amazon.end()
- Returns
{}
- Return type
dict
Quit
It quits the bot-studio application runing in background.
Note
You will need to import bot-studio library again to start application.
- amazon.quit()
- Returns
{}
- Return type
dict