Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k 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 Reply

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'])

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...