简体   繁体   English

如何在python3中使用多条件findAll?

[英]How to use multiple condition findAll in python3?

ex) In html 例如)在HTML

<tr class='odd'> ~~~~ 
<tr class='even'> ~~~~

I am studying Crawling using Beautiful soup in python3. 我正在研究使用python3中的Beautiful汤进行抓取。

I want to 'odd' class and 'even' class 我想上“奇”班和“偶”班

So, I wrote that 所以,我写了

url = 'http:// ~~~~'
src_code = requests.get(url)
plain_txt = src_code.text
soup = BeautifulSoup(plain_txt, 'lxml')

trTag = soup.findAll('tr', class_ = 'odd' | 'even')

But, 但,

trTag = soup.findAll('tr', class_ ='odd' | 'even')

in this line, error. 在这一行,错误。

I want to find odd class and even class at one go. 我想一次找到奇怪的班级,甚至找到班级。

Is it impossible? 不可能吗

I have to write trTag = soup.findAll('tr',class_='odd') trTag = soup.findAll('tr',class_='even') 我必须写trTag = soup.findAll('tr',class _ ='odd')trTag = soup.findAll('tr',class _ ='even')

separately? 分别?

I want to learn. 我想学习。

trTag = soup.findAll('tr', class_ =['odd', 'even'])

Document 文献

If you pass in a list, Beautiful Soup will allow a string match against any item in that list. 如果您传递一个列表,Beautiful Soup将允许该列表中的任何项目进行字符串匹配。

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

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