Hi I am new to programming, I am currently reading AutomateTheBoringStuff and I come across this error while web scrapping UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("html5lib").
It a simple web scrapping program that open the first 5 website link of the word that I writted in my input program.
my code:
import webbrowser, requests, bs4
ans = input()
print('Googling...') # display text while downloading the Google page
res = requests.get('http://google.com/search?q=' + ans)
res.raise_for_status()
# Retrieve top search result links.
soup = bs4.BeautifulSoup(res.text)
# Open a browser tab for each result.
linkElems = soup.select('.r a')
# Open a browser tab for each result.
numOpen = min(5, len(linkElems))
for i in range(numOpen):
webbrowser.open('http://google.com' + linkElems[i].get('href'))
When I write html.parser on this line : soup = bs4.BeautifulSoup(res.text, "html.parser")
The error is no longer here but the program doesn't open my web tab. So I guess it not the right way to resolve this Thanks for helping!
Aucun commentaire:
Enregistrer un commentaire