My intent
我想要刮掉用户从github使用beautiful soup with python提交。
我的问题
得到none
作为我的脚本的结果。
我的代码
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)
发生了什么?
你在使用"wild mix"在你的find()
中,这不会导致你期望找到的元素,这就是为什么你得到一个None
如何修复?
使用css选择器来链接您正在寻找的部分,在这种情况下,它将在提交前选择<svg>
及其下一个包含<strong>
的<span>
元素:
soup.select_one('svg.octicon.octicon-history + span strong').text
输出(在我请求的时刻)
1,664