简体   繁体   English

如何使用 Python 的 Beautiful Soup 来查找自定义属性的值?

[英]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 . data3456div的自定义属性。 How can I scan the html looking for "data3456" and find "some value"?如何扫描 html 寻找“data3456”并找到“一些价值”?

You can use similar logic which is used here: How to use CSS selectors to retrieve specific links lying in some class using BeautifulSoup?您可以使用此处使用的类似逻辑: 如何使用 CSS 选择器来检索使用 BeautifulSoup 的 class 中的特定链接? . .

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.它涵盖了我认为您正在寻找的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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