3 回答

TA貢獻(xiàn)1864條經(jīng)驗 獲得超6個贊
該腳本將打印<img>“頂級操作員”部分的所有標(biāo)題:
from bs4 import BeautifulSoup as bs
import requests
bsURL = "https://r6.tracker.network/profile/pc/Spoit.GODSENT"
respinse = requests.get(bsURL)
html = bs(respinse.text, 'html.parser')
# find Top Operators tag
operators = html.find(class_='trn-defstat__name', text='Top Operators')
for img in operators.find_next('div').find_all('img'):
print(img['title'])
印刷:
ASH
J?GER
BANDIT
或者使用CSS:
for img in html.select('.trn-defstat__name:contains("Top Operators") + * img'):
print(img['title'])

TA貢獻(xiàn)1806條經(jīng)驗 獲得超5個贊
只需使用.get()函數(shù)獲取屬性并傳入屬性名稱即可。
pip install html5lib
我建議你使用它,我相信它是一個更好的解析器。
from bs4 import BeautifulSoup as bs
import requests
bsURL = "https://r6.tracker.network/profile/pc/Spoit.GODSENT"
respinse = requests.get(bsURL)
html = bs(respinse.content, 'html5lib')
container = html.find("div", class_= "trn-defstat mb0 top-operators")
imgs = container.find_all("img")
for img in imgs:
print(img.get("title"))
我似乎不明白您想要抓取網(wǎng)站的哪一部分,但請注意有時會先獲取blockhtml 代碼,其中包含您想要抓取的詳細(xì)信息:)

TA貢獻(xiàn)1777條經(jīng)驗 獲得超10個贊
只需使用.get()函數(shù)獲取屬性并傳入屬性名稱即可。
pip install html5lib
我建議你使用它,我相信它是一個更好的解析器。
from bs4 import BeautifulSoup as bs
import requests
bsURL = "https://r6.tracker.network/profile/pc/Spoit.GODSENT"
respinse = requests.get(bsURL)
html = bs(respinse.content, 'html5lib')
container = html.find("div", class_= "trn-defstat mb0 top-operators")
imgs = container.find_all("img")
for img in imgs:
print(img.get("title"))
我似乎不明白您想要抓取網(wǎng)站的哪一部分,但請注意有時會先獲取blockhtml 代碼,其中包含您想要抓取的詳細(xì)信息:)
添加回答
舉報