Getting none in beautiful soup web-scraping

Viewed 110

My intend

I want to scrape commits of user from github using beautiful soup with python.

My issue

Getting none as result of my script.

My code

from bs4 import BeautifulSoup
import requests

html = requests.get('https://github.com/pnp/cli-microsoft365').text
soup = BeautifulSoup(html, 'html.parser')
commits = soup.select_one('svg.octicon.octicon-history + span strong').text
print(commits)

1 Answers

What happens?

Your using a "wild mix" in your find() and this will not lead to the element you are expected to find, thats why you get a None

How to fix?

Use the css selector to chain the parts you are looking for, in this case it will pick the <svg> in front of commits and its next <span> element that contains the <strong>:

soup.select_one('svg.octicon.octicon-history + span strong').text 

Output (in moment of my request)

1,664
Related