This should be fairly straightforward. I want to count the links created from a search on a webpage. In this example, search for "gwen stefani" on Stack Overflow. As of the time of writing, the number of results is 15.
import bs4 # beautiful soup 4
import requests
import webbrowser
url = "https://stackoverflow.com/search?q=gwen+stefani"
myURL = url
webbrowser.open(myURL)
page = requests.get(url).text
r = requests.get(myURL)
html_content = r.text
soup = bs4.BeautifulSoup(html_content, "html.parser")
print soup.title
for link in soup.find_all("a"):
print(link.get("href"))
When the links are printed out, it doesn't contain any of the results mentioned. I'm new to the soup, and I'm not sure where I'm going wrong at this point.