when i was typing on of AI sweigart example on how to use bs4 function combined with webbrowser function to start multiple web pages at once i had a problem that webbrowser.open function doesn’t work proprly in the
code i tried to the run the function outside the loop and it works well but when I am putting it in the loop it doesn’t work
first i tried to reinstall webbrowser function,but to no avail.
then i tried to start webbrowser.open
function outside the loop and it worked
maybe the problem is in the for loop condition
I am now working in python 3.11 f you are wondering
sorry I am still new to coding so sorry for the truble and I hope I can ge soe help
here is the code
import sys, webbrowser ,requests,bs4,os
print("Googling...")
res = requests.get("https://www.google.com/search?client=firefox-b-d&q=" + " ".join(sys.argv[1:]))
res.raise_for_status()
soup = bs4.BeautifulSoup(res.text, features="html.parser")
links = soup.select(".r a")
Numopen = min(3,len(links))
for i in range(Numopen):
webbrowser.open("https://www.google.com"+links[i].get("herf"))
Omer Elga3afri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.