Skip to content Skip to sidebar Skip to footer

Python Beautifulsoup Getting Attribute Value

I'm having difficulty getting the proper syntax to extract the value of an attribute in Beautifulsoup with HTML 5.0. So I've isolated the occurrence of a tag in my soup using the p

Solution 1:

You can access the attrs using key-value pair

Ex:

from bs4 import BeautifulSoup
s = """<span class="invisible" data-datenews="2018-05-25 06:02:19" data-idnews="2736625" id="horaCompleta"></span>"""
soup = BeautifulSoup(s, "html.parser")
print(soup.span["data-datenews"])

Output:

2018-05-25 06:02:19

Post a Comment for "Python Beautifulsoup Getting Attribute Value"