This is the fourth script in 'Python Scripts' series.
You can have a look at previous scripts by following the links given below.
Python Script 3: Validate and format JSON string
Python Script 2: Crawling all emails from a website
Python Script 1: Convert ebook from one format to another
As the title suggests, this script is used to open the top 10 Google search results in different tabs for the provided keyword.
Author: Anurag Rana
Usage: python google.py <keyword>
Description: Script googles the keyword and opens top 10(max) search results in separate tabs in the browser
Usage: python filename.py keyword
Tested with Python3
if len(sys.argv) > 1:
keyword = ' '.join(sys.argv[1:])
# if no keyword is entered, the script would
# search for the keyword copied in the clipboard
keyword = pyperclip.paste()
res = requests.get('https://google.com/search?q='+keyword)
soup = bs4.BeautifulSoup(res.text,'lxml')
links = soup.select('.r a')
tab_counts = min(10, len(links))
for i in range(tab_counts):
webbrowser.open('https://google.com' + links[i].get('href'))
I am using this same concept at my work. Every day I have to open 8 applications (slack, JIRA, Gitlab, Facebook, StackOverflow, Jenkins UI, Outlook and Personal Email) in my browser. So instead of opening each application one by one, I just run the script and all these applications are opened in different tabs saving a few seconds.