Python Beautifulsoup Getting Attribute Value

后端 未结 1 1829
闹比i
闹比i 2020-12-11 20:32

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

相关标签:
1条回答
  • 2020-12-11 21:02

    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
    
    0 讨论(0)
提交回复
热议问题