简体   繁体   中英

How can I use Python's Beautiful Soup to find the value of a custom attribute?

For example:

div data3456 = "some value"

data3456 is a custom attribute for the div . How can I scan the html looking for "data3456" and find "some value"?

You can use similar logic which is used here: How to use CSS selectors to retrieve specific links lying in some class using BeautifulSoup? .

Try this:

for el in upcoming_events_div.select('div[data3456]'):
    print el['data3456']

May I suggest this article? It covers, what I think, you are looking for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM