Reputation: 67
the text is :
<div class="fi-mu-list today" data-matchesdate="20180619">
I want to extract 20180619
from this.
I tried : 1)
mat = soup.select("div.fi-mu-list today > span.fi-mu-list__head__date")
print(mat["data-matchesdate"])
output : TypeError: list indices must be integers or slices, not str
2)
also tried print(mat)
output : []
Upvotes: 0
Views: 53
Reputation: 71471
You can use 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']
Output:
'20180619'
Upvotes: 1