Automate Google 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 things. You can download the source code from here(see here)

It uses selenium to automate the things. You can use its inbuilt functions 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

google=bot_studio.google()
or
google=bot_studio.google(headless=True,...)

It will return the object which you can further use to call google functions and opens a 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 google:-

Search Images

It searches the keyword passed in keyword on google in images.

body: returns data

success_score: api success rate

errors: errors encountered in api

Here is the code:-

google.search_images(keyword='shoes')
Parameters

keyword (str) – Keyword which need to be search on google

Returns

{“body”: {}, “success_score”: “100”, “errors”: []}

Return type

dict

Click Next

It clicks on Next page on search results page.

body: returns data

success_score: api success rate

errors: errors encountered in api

Here is the code:-

google.click_next()
Returns

{“body”: {}, “success_score”: “100”, “errors”: []}

Return type

dict

Search Results

It fetches the links and titles of the search results page.

body: returns data

success_score: api success rate

errors: errors encountered in api

Here is the code:-

google.search_results()
Returns

{“body”: [{‘Title’: ‘Title’, ‘Link’: ‘Link’, ‘Desc’: ‘Desc’}], “success_score”: “100”, “errors”: []}

Return type

dict

Search Image Results

It fetches the links, titles and image src of the search results images.

body: returns data

success_score: api success rate

errors: errors encountered in api

Here is the code:-

google.search_image_results()
Returns

{“body”: [{‘Title’: ‘Title’, ‘Link’: ‘Link’, ‘ImageLink’: ‘ImageLink’}], “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.

google.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.

google.get_page_title()
Returns

{“pagetitle”:”google”}

Return type

dict

Get Page Source

It returns the pagesource of page opened.

google.get_page_source()
Returns

{“pagesource”:”pagesource”}

Return type

dict

Get Current Url

It returns the pagesource of page opened.

google.get_current_url()
Returns

{“url”:”url”}

Return type

dict

Reload

It reloads the page opened.

google.reload()
Returns

{}

Return type

dict

Keypress

It perform the keypress passed.

google.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.

google.scroll()
Returns

{}

Return type

dict

End

It ends the google session and close the automated chromedriver.

Note

You will need to create google object again after end().

google.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.

google.quit()
Returns

{}

Return type

dict

google-site-verification: google733358e4a0a39a02.html