我的意圖
我想使用帶有 python 的漂亮湯從github 中洗掉用戶的提交。
我的問題
獲得none我的腳本的結果。
我的代碼
from bs4 import BeautifulSoup
import requests
html = requests.get('https://github.com/pnp/cli-microsoft365').text
soup = BeautifulSoup(html, 'html.parser')
commits = soup.find('strong', class_='repo-content-pjax-container > div > div.gutter-condensed.gutter-lg.flex-column.flex-md-row.d-flex > div.flex-shrink-0.col-12.col-md-9.mb-4.mb-md-0 > div.Box.mb-3 > div.Box-header.position-relative > div > div:nth-child(4) > ul > li > a > span > strong')
print(commits)
uj5u.com熱心網友回復:
發生什么了?
你在你的find()和這不會導致你期望找到的元素中使用“野生混合” ,這就是為什么你得到一個None
怎么修?
使用 css 選擇器鏈接您要查找的部分,在這種情況下,它將選擇<svg>提交前的部分及其<span>包含以下內容的下一個元素<strong>:
soup.select_one('svg.octicon.octicon-history span strong').text
輸出(在我請求的那一刻)
1,664
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/319117.html
