2016-12-28 89 views
-1

的类名的名单,我得到的是从beautifulsoup4: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 

我看着BF 4文档和几个栈有关检索班级名称但没有成功的问题。我无法找回这些课程。 (我知道我可以解析字符串来获得结果,但我很想了解bf4)。

+0

我试图超过20组合使用var.find( 'TD')和变种( “TR”,{ “类”[])变种( 'td.class')等 –

+0

@depperm我想你低估了我。感谢elrull,我找到了我正在寻找的.join(s ['class'])。我很想知道我可以在bf4文档中找到它的位置:https://www.crummy.com/software/BeautifulSoup/bs4/doc/ –

回答

1
for s in soup.find_all('td'): 
    print ''.join(s['class']).strip(), s.text 
+0

python35语法: for dayPrecipit.find_all('td '): print(''。join(s ['class'])。strip(),s.text) –

+0

'''.join(listToConvert)'将列表转换为字符串http://stackoverflow.com/questions/5618878/how-to-convert-list-to-string –

+0

'variable ['class']'为寻找文档的人发送类名 –