I am having a little trouble trying to get this performed for output after searching. It did not happen anything such as opening web browsers. Am I doing something wrong? Your tips and advice would be so much appreciated. Here's the code I entered from the above book:
#! /usr/bin/env python3
# searchpypi.py - Opens several search results.
import requests, sys, webbrowser, bs4
print('Searching...') # display text while downloading the search result page
res = requests.get('https://www.duckduckgo.com/search?q='+''.join(sys.argv[1:]))
res.raise_for_status()
# TODO: Retrieve top search result links.
soup = bs4.BeautifulSoup(res.text, 'html.parser')
# TODO: Open a browser tab for each result.
linkElems = soup.select('.package-snippet')
for elem in linkElems[:5]: # first 5 elements in list
urlToOpen = 'https://pypi.org' + elem.get('href')
print('Opening', urlToOpen)
webbrowser.open(urlToOpen)