beautifulsoup4:如何检索特定标签的类名列表 [英] beautifulsoup4: how to retrieve a list of the class name of specific tag
本文介绍了beautifulsoup4:如何检索特定标签的类名列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从beautifulsoup4中得到了
I get that from beautifulsoup4:
<tr class="Details"> <td class=" s-12-to-15 ">ABC</td> <td class="s-15-to-18 ">DEF</td> <td class=" s-18-to-21 ">GHI</td></tr>
我如何获得:
s-12-to-15 ABC
s-15-to-18 DEF
s-18-to-21 GHI
我研究了bf4文档和一些有关检索类名的堆栈问题,但没有成功.我无法检索这些类. (我知道我可以解析字符串以获取结果,但是我有兴趣了解bf4).
I looked into bf4 documentation and several stack questions about retrieving class name but without success. I can't the way to retrieve these class. (I know I could parse the string to get the result but I'm interested to learn about bf4).
推荐答案
for s in soup.find_all('td'):
print ''.join(s['class']).strip(), s.text
这篇关于beautifulsoup4:如何检索特定标签的类名列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文