Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

beautifulsoup - Python web-scraping countdown timer values

I am trying to scrape data from the following <countdown> element, specifically I am trying to get the values from formatted_date. I am not getting any luck and it is just printing None.

<countdown current_time="1611585537797" date="1611603000" listing="f446d440-9d45-4e48-bf93-69c5e117fac2" formatted_date="25th January 2021 19:30:00"></countdown>

Any ideas?

question from:https://stackoverflow.com/questions/65888255/python-web-scraping-countdown-timer-values

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

try this: We can access a tag’s attributes by treating it like a dictionary.

from bs4 import BeautifulSoup

html = """<countdown current_time="1611585537797" date="1611603000" listing="f446d440-9d45-4e48-bf93-69c5e117fac2" formatted_date="25th January 2021 19:30:00"></countdown>"""

soup = BeautifulSoup(html, 'lxml')

tag = soup.countdown
print(tag.attrs['formatted_date'])

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...