亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Python 中的網絡爬蟲

Python 中的網絡爬蟲

四季花海 2023-09-05 17:34:09
我的問題是是否有可能獲得一個在這樣的范圍內的數字:<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)


查看完整回答
反對 回復 2023-09-05
  • 1 回答
  • 0 關注
  • 168 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號