Extracting an attribute value with beautifulsoup

前端 未结 9 2060
故里飘歌
故里飘歌 2020-11-22 04:38

I am trying to extract the content of a single \"value\" attribute in a specific \"input\" tag on a webpage. I use the following code:

import urllib
f = urll         


        
9条回答
  •  天命终不由人
    2020-11-22 05:31

    You could try to use the new powerful package called requests_html:

    from requests_html import HTMLSession
    session = HTMLSession()
    
    r = session.get("https://www.bbc.co.uk/news/technology-54448223")
    date = r.html.find('time', first = True) # finding a "tag" called "time"
    print(date)  # you will have: 
    # To get the text inside the "datetime" attribute use:
    print(date.attrs['datetime']) # you will get '2020-10-07T11:41:22.000Z'
    

提交回复
热议问题