文字是:
<div class="fi-mu-list today" data-matchesdate="20180619">
我想从中提取20180619
。
我试过了: 1)
mat = soup.select("div.fi-mu-list today > span.fi-mu-list__head__date")
print(mat["data-matchesdate"])
输出:TypeError: list indices must be integers or slices, not str
2)
还尝试了print(mat)
输出:[]
答案 0 :(得分:1)
您可以使用BeautifulSoup.find
:
from bs4 import BeautifulSoup as soup
s = '<div class="fi-mu-list today" data-matchesdate="20180619">'
result = soup(s, 'html.parser').find('div')['data-matchesdate']
输出:
'20180619'