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
366 views
in Technique[技术] by (71.8m points)

python - bs4 BeautifulSoup - can't find what looks like custom tag to save my life

I'm admittedly beginner to intermediate with Python and novice to BeautifulSoup/web-scraping. However, I have successfully built a couple of scrapers. Normal tags = no problem (e.g., div, a, li, etc)

However, can't find how to reference this tag with .select or .find or attrs="" or anything:

.......... <react type="sad" msgid="25314120" num="2" ..........

I ultimately want what looks like the "num" attribute from whatever this ghastly thing is ... a "react" tag (though I don't think that's a thing?)?

question from:https://stackoverflow.com/questions/65557453/bs4-beautifulsoup-cant-find-what-looks-like-custom-tag-to-save-my-life

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

1 Reply

0 votes
by (71.8m points)

.find() works the same way as you'd find other tags such as div, p and a tags. Therefore, we search for the 'react' tag.

react_tag = soup.find('react')

Then, access the num attribute like so.

num_value = react_tag['num']

Should print out:

2

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

1.4m articles

1.4m replys

5 comments

57.0k users

...