SlideShare a Scribd company logo
1 of 7
Project: “I’m Feeling Lucky”
Google Search
Guided by,
Dr. Srivani P
Assistant professor
Presented by,
B C Narendra
5th sem CSE
Introduction
• Whenever I search a topic on Google, I
don’t look at just one search result at a
time. By middle-clicking a search result
link (or clicking while holding ctrl), I open
the first several links in a bunch of new
tabs to read later.
• It would be nice if I could simply
type a search term on the command line
and have my computer automatically
open a browser with all the top search
results in new tabs.
•
This is what your program does:
 Gets search keywords from the command line
arguments.
 Retrieves the search results page.
 Opens a browser tab for each result.
This means your code will need to do the following:
 Read the command line arguments from sys.argv.
 Fetch the search result page with the requests
module.
 Find the links to each search result.
 Call the webbrowser.open() function to open the
web browser
Open a new file editor window and save it as lucky.py.
Step 1: Get the Command Line Arguments and Request the Search Page
Before coding anything,you first need to know the URL of the search result
page. You can see that the result page has a URL like
https://www.google.com/search?q=SEARCH_TERM_HERE.
The requests module can download this page and then you can use Beautiful
Soup to find the search result links in the HTML. Finally, you’lluse the
webbrowser module to open those links in browser tabs.
import requests, sys, webbrowser, bs4
print('Googling') # display text while downloading the Google page
res = requests.get('http://google.com/search?q=' + ' '.join(sys.argv[1:]))
res.raise_for_status()
Step 2: Find All the Results
Now you need to use BeautifulSoup to extract the top search result links
from your downloadedHTML. You can’t just search for all tags, because there
are lots of links you don’t care about in the HTML. Instead, you must inspect
the search result page with the browser’s developertools to try to find a
selector that will pick out only the links you want.
After doing a Google search for Beautiful Soup, you can open the browser’s
developertools and inspect some of the link elements on the page. They look
incrediblycomplicated, somethinglike this: BeautifulSoup: We called him
Tortoise because he taught us.
soup = bs4.BeautifulSoup(res.text )
linkElems = soup.select('.r a')
Step 3: Open Web Browsers for Each Result
Finally, we’ll tell the program to open web browser tabs for our results. Add
the following to the end of your program:
linkElems = soup.select('.r a')
numOpen = min(5, len (linkElems))
for i in range(numOpen):
webbrowser.open('http://google.com' + linkElems[i].get('href'))
By default, you open the first five search results in new tabs using the
webbrowser module. However, the user may have searched for something
that turned up fewer than five results.
On each iteration of the loop, you use webbrowser.open()to open a new tab in
the web browser.
Thank You

More Related Content

Similar to Presentation_ADP.pptx

Week 9 10 ppt-how_searchworks
Week 9 10 ppt-how_searchworksWeek 9 10 ppt-how_searchworks
Week 9 10 ppt-how_searchworkscarolyn oldham
 
Scrape box presentation
Scrape box presentationScrape box presentation
Scrape box presentationElephate1
 
Ultimate Guide to White Hat SEO using Scrapebox
Ultimate Guide to White Hat SEO using ScrapeboxUltimate Guide to White Hat SEO using Scrapebox
Ultimate Guide to White Hat SEO using ScrapeboxŁukasz Rogala
 
How to Scrape Amazon Best Seller Lists with Python and BeautifulSoup.pdf
How to Scrape Amazon Best Seller Lists with Python and BeautifulSoup.pdfHow to Scrape Amazon Best Seller Lists with Python and BeautifulSoup.pdf
How to Scrape Amazon Best Seller Lists with Python and BeautifulSoup.pdfProductdata Scrape
 
Introduction of Search Engine & working process.pdf
Introduction of Search Engine & working process.pdfIntroduction of Search Engine & working process.pdf
Introduction of Search Engine & working process.pdfSAMBaquibillahSagor
 
How to Scrape Amazon Best Seller Lists with Python and BeautifulSoup.pptx
How to Scrape Amazon Best Seller Lists with Python and BeautifulSoup.pptxHow to Scrape Amazon Best Seller Lists with Python and BeautifulSoup.pptx
How to Scrape Amazon Best Seller Lists with Python and BeautifulSoup.pptxProductdata Scrape
 
Search Engine Optimization (SEO)
Search Engine Optimization (SEO)Search Engine Optimization (SEO)
Search Engine Optimization (SEO)Nandu B Rajan
 
Thuvien it.org--seo-workflow-link-assistant.com
Thuvien it.org--seo-workflow-link-assistant.comThuvien it.org--seo-workflow-link-assistant.com
Thuvien it.org--seo-workflow-link-assistant.comMinh Nguyễn
 
Google ppt by amit
Google ppt by amitGoogle ppt by amit
Google ppt by amitDAVV
 
Web driver selenium simplified
Web driver selenium simplifiedWeb driver selenium simplified
Web driver selenium simplifiedVikas Singh
 
Keyword basics-final
Keyword basics-finalKeyword basics-final
Keyword basics-finalpdrlvn74
 
Search Engine Optimization
Search Engine OptimizationSearch Engine Optimization
Search Engine Optimizationshrishail uttagi
 
Social buzz club
Social buzz clubSocial buzz club
Social buzz clubLori Gama
 
SEO Training in Hyderabad | SEO Classes in Hyderbad | SEO Coaching in Hyde...
SEO Training in Hyderabad |  SEO  Classes in Hyderbad | SEO Coaching in  Hyde...SEO Training in Hyderabad |  SEO  Classes in Hyderbad | SEO Coaching in  Hyde...
SEO Training in Hyderabad | SEO Classes in Hyderbad | SEO Coaching in Hyde...Prasad Reddy
 

Similar to Presentation_ADP.pptx (20)

Week 9 10 ppt-how_searchworks
Week 9 10 ppt-how_searchworksWeek 9 10 ppt-how_searchworks
Week 9 10 ppt-how_searchworks
 
Modern JavaScript and SEO
Modern JavaScript and SEOModern JavaScript and SEO
Modern JavaScript and SEO
 
Il 01-search engines
Il 01-search enginesIl 01-search engines
Il 01-search engines
 
Scrape box presentation
Scrape box presentationScrape box presentation
Scrape box presentation
 
Ultimate Guide to White Hat SEO using Scrapebox
Ultimate Guide to White Hat SEO using ScrapeboxUltimate Guide to White Hat SEO using Scrapebox
Ultimate Guide to White Hat SEO using Scrapebox
 
Google
GoogleGoogle
Google
 
How to Scrape Amazon Best Seller Lists with Python and BeautifulSoup.pdf
How to Scrape Amazon Best Seller Lists with Python and BeautifulSoup.pdfHow to Scrape Amazon Best Seller Lists with Python and BeautifulSoup.pdf
How to Scrape Amazon Best Seller Lists with Python and BeautifulSoup.pdf
 
Introduction of Search Engine & working process.pdf
Introduction of Search Engine & working process.pdfIntroduction of Search Engine & working process.pdf
Introduction of Search Engine & working process.pdf
 
How to Scrape Amazon Best Seller Lists with Python and BeautifulSoup.pptx
How to Scrape Amazon Best Seller Lists with Python and BeautifulSoup.pptxHow to Scrape Amazon Best Seller Lists with Python and BeautifulSoup.pptx
How to Scrape Amazon Best Seller Lists with Python and BeautifulSoup.pptx
 
Search Engine Optimization (SEO)
Search Engine Optimization (SEO)Search Engine Optimization (SEO)
Search Engine Optimization (SEO)
 
Thuvien it.org--seo-workflow-link-assistant.com
Thuvien it.org--seo-workflow-link-assistant.comThuvien it.org--seo-workflow-link-assistant.com
Thuvien it.org--seo-workflow-link-assistant.com
 
Google ppt by amit
Google ppt by amitGoogle ppt by amit
Google ppt by amit
 
Web driver selenium simplified
Web driver selenium simplifiedWeb driver selenium simplified
Web driver selenium simplified
 
Keyword basics-final
Keyword basics-finalKeyword basics-final
Keyword basics-final
 
Search Engine Optimization
Search Engine OptimizationSearch Engine Optimization
Search Engine Optimization
 
Hacking
HackingHacking
Hacking
 
Social buzz club
Social buzz clubSocial buzz club
Social buzz club
 
Lesson 4.pdf
Lesson 4.pdfLesson 4.pdf
Lesson 4.pdf
 
Lvr ppt
Lvr pptLvr ppt
Lvr ppt
 
SEO Training in Hyderabad | SEO Classes in Hyderbad | SEO Coaching in Hyde...
SEO Training in Hyderabad |  SEO  Classes in Hyderbad | SEO Coaching in  Hyde...SEO Training in Hyderabad |  SEO  Classes in Hyderbad | SEO Coaching in  Hyde...
SEO Training in Hyderabad | SEO Classes in Hyderbad | SEO Coaching in Hyde...
 

More from mukul narayana

Note for Artificial Neural Network - ANN by Aman Kumar _ LectureNotes.pdf
Note for Artificial Neural Network - ANN by Aman Kumar _ LectureNotes.pdfNote for Artificial Neural Network - ANN by Aman Kumar _ LectureNotes.pdf
Note for Artificial Neural Network - ANN by Aman Kumar _ LectureNotes.pdfmukul narayana
 
churchturingthesis-160906170827.pptx
churchturingthesis-160906170827.pptxchurchturingthesis-160906170827.pptx
churchturingthesis-160906170827.pptxmukul narayana
 
Energy Management Presentation (1).ppt
Energy Management Presentation (1).pptEnergy Management Presentation (1).ppt
Energy Management Presentation (1).pptmukul narayana
 

More from mukul narayana (6)

Note for Artificial Neural Network - ANN by Aman Kumar _ LectureNotes.pdf
Note for Artificial Neural Network - ANN by Aman Kumar _ LectureNotes.pdfNote for Artificial Neural Network - ANN by Aman Kumar _ LectureNotes.pdf
Note for Artificial Neural Network - ANN by Aman Kumar _ LectureNotes.pdf
 
Ch11.ppt
Ch11.pptCh11.ppt
Ch11.ppt
 
ch15.ppt
ch15.pptch15.ppt
ch15.ppt
 
churchturingthesis-160906170827.pptx
churchturingthesis-160906170827.pptxchurchturingthesis-160906170827.pptx
churchturingthesis-160906170827.pptx
 
Ch11.ppt
Ch11.pptCh11.ppt
Ch11.ppt
 
Energy Management Presentation (1).ppt
Energy Management Presentation (1).pptEnergy Management Presentation (1).ppt
Energy Management Presentation (1).ppt
 

Recently uploaded

Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilVinayVitekari
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxSCMS School of Architecture
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdfKamal Acharya
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiessarkmank1
 
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptxrouholahahmadi9876
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdfKamal Acharya
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksMagic Marks
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Servicemeghakumariji156
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxmaisarahman1
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxSCMS School of Architecture
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...jabtakhaidam7
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdfKamal Acharya
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...drmkjayanthikannan
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...HenryBriggs2
 

Recently uploaded (20)

Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech Civil
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic Marks
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
 

Presentation_ADP.pptx

  • 1. Project: “I’m Feeling Lucky” Google Search Guided by, Dr. Srivani P Assistant professor Presented by, B C Narendra 5th sem CSE
  • 2. Introduction • Whenever I search a topic on Google, I don’t look at just one search result at a time. By middle-clicking a search result link (or clicking while holding ctrl), I open the first several links in a bunch of new tabs to read later. • It would be nice if I could simply type a search term on the command line and have my computer automatically open a browser with all the top search results in new tabs. •
  • 3. This is what your program does:  Gets search keywords from the command line arguments.  Retrieves the search results page.  Opens a browser tab for each result. This means your code will need to do the following:  Read the command line arguments from sys.argv.  Fetch the search result page with the requests module.  Find the links to each search result.  Call the webbrowser.open() function to open the web browser Open a new file editor window and save it as lucky.py.
  • 4. Step 1: Get the Command Line Arguments and Request the Search Page Before coding anything,you first need to know the URL of the search result page. You can see that the result page has a URL like https://www.google.com/search?q=SEARCH_TERM_HERE. The requests module can download this page and then you can use Beautiful Soup to find the search result links in the HTML. Finally, you’lluse the webbrowser module to open those links in browser tabs. import requests, sys, webbrowser, bs4 print('Googling') # display text while downloading the Google page res = requests.get('http://google.com/search?q=' + ' '.join(sys.argv[1:])) res.raise_for_status()
  • 5. Step 2: Find All the Results Now you need to use BeautifulSoup to extract the top search result links from your downloadedHTML. You can’t just search for all tags, because there are lots of links you don’t care about in the HTML. Instead, you must inspect the search result page with the browser’s developertools to try to find a selector that will pick out only the links you want. After doing a Google search for Beautiful Soup, you can open the browser’s developertools and inspect some of the link elements on the page. They look incrediblycomplicated, somethinglike this: BeautifulSoup: We called him Tortoise because he taught us. soup = bs4.BeautifulSoup(res.text ) linkElems = soup.select('.r a')
  • 6. Step 3: Open Web Browsers for Each Result Finally, we’ll tell the program to open web browser tabs for our results. Add the following to the end of your program: linkElems = soup.select('.r a') numOpen = min(5, len (linkElems)) for i in range(numOpen): webbrowser.open('http://google.com' + linkElems[i].get('href')) By default, you open the first five search results in new tabs using the webbrowser module. However, the user may have searched for something that turned up fewer than five results. On each iteration of the loop, you use webbrowser.open()to open a new tab in the web browser.