1

ex) In html

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

I am studying Crawling using Beautiful soup in python3.

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')

separately?

I want to learn.

StackQ
  • 99
  • 1
  • 11
  • Oh, I got it. http://stackoverflow.com/questions/18725760/beautifulsoup-findall-given-multiple-classes Thanks – StackQ Jan 24 '17 at 02:04

1 Answers1

3
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.

宏杰李
  • 11,820
  • 2
  • 28
  • 35