本文介绍了包括BeautifulSoup4中的findAll多个类名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个python脚本一行code的如下图所示。

I have a line of code in a python script as shown below

for summaries in soup.findAll('div',{'class':'cb-lv-scrs-col cb-font-12 cb-text-complete'}):
#do something with summaries

不过,我想总结还包括一个名为 CB-SCAG-MTCH状态CB-文本INPROGRESS另一个类从 DIV 笔数

我曾尝试以低于这里给出 - BeautifulSoup的findAll()给出多个类?

I have tried the below as given here - BeautifulSoup findAll() given multiple classes?

for summaries in soup.findAll('div',{'class':['cb-lv-scrs-col cb-font-12 cb-text-complete','cb-scag-mtch-status cb-text-inprogress']}):
#do something with summaries

但是这是行不通的。这是什么问题,如何解决呢?

but this is not working. What is the problem and how do i fix it?

推荐答案

我会做一个简单的:

soup.select('div[class="cb-lv-scrs-col cb-font-12 cb-text-complete"],div[class="cb-scag-mtch-status cb-text-inprogress"]')

不过,我怀疑你真的需要还是应该检查所有的类present的一个元素,那不是足够的:

but, I doubt you really need or should check all of the classes present on an element, would not that be sufficient:

soup.select('div.cb-text-complete,div.cb-text-inprogress')

这篇关于包括BeautifulSoup4中的findAll多个类名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 17:37