Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python beautifulsoup4:如何检索特定标记的类名列表_Python_Python 3.x_Beautifulsoup - Fatal编程技术网

Python beautifulsoup4:如何检索特定标记的类名列表

Python beautifulsoup4:如何检索特定标记的类名列表,python,python-3.x,beautifulsoup,Python,Python 3.x,Beautifulsoup,我从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> 我查阅了bf4文档和几个关于检索类名的堆栈问题,但没有成功。我无法找到检索这些类的方法。(我知道我可以解析字

我从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>

我查阅了bf4文档和几个关于检索类名的堆栈问题,但没有成功。我无法找到检索这些类的方法。(我知道我可以解析字符串以获得结果,但我有兴趣了解bf4)。

我尝试了20多种组合,使用var.find('td')和var.('tr',{class'[])var.('td.class')等@depperm我猜你否决了我。多亏了elrull,我找到了.join(s['class'])我正在寻找。我想知道在bf4文档中哪里可以找到它:python35语法:dayPrecipit中的s.find_all('td'):print(''.join(s['class']).strip(),s.text)the
'.join(listToConvert)
将列表转换为字符串
变量['class']
为查找文档的人发送类名:
s-12-to-15 ABC
s-15-to-18 DEF
s-18-to-21 GHI
for s in soup.find_all('td'):
    print ''.join(s['class']).strip(), s.text