我的問題是是否有可能獲得一個在這樣的范圍內的數字:<html junk> <div class="test"> <span> 55 </span> </div></html junk>正如您所看到的,span 沒有類或 id。我當前的代碼只是抓取工具的默認代碼(刪除了用戶代理和 URL):import requestsfrom bs4 import BeautifulSoupURL = ''headers = {"User-Agent": ''}page = requests.get(URL, headers=headers)soup = BeautifulSoup(page.content, 'html.parser')#Here is where the "55" should be found (the number is going to change over time so im not excactly looking for ittitle = soup.find('') print(title)
1 回答

UYOU
TA貢獻1878條經驗 獲得超4個贊
如果我正確理解你的問題,你正在嘗試獲取兩個跨度標簽之間的數字?如果是這樣,你可以這樣做。
import requests
from bs4 import BeautifulSoup
URL = ''
headers = {"User-Agent": ''}
page = requests.get(URL, headers=headers)
soup = BeautifulSoup(page.text, 'html.parser')
#Here is where the "55" should be found (the number is going to change over time so im not excactly looking for it
title = soup.find('span').getText()
print(title)
添加回答
舉報
0/150
提交
取消