2

My problem is that i have to scrape a website which has:

<div class="xyz tab"> blah blah </div>

And another div in the same website having which is as follows:

<div class="xyz">blah blah</div>

to scrape a website without space i can use this

pyquery('.xyz').text()

but for with space what should i do???

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
Ravinder Baid
  • 395
  • 1
  • 15

1 Answers1

6

If you need to check for both xyz and tab classes, you can use .xyz.tab:

>>> from pyquery import PyQuery as pq
>>> data = """
... <div>
...     <div class="xyz tab">test1</div>
...     <div class="xyz">test2</div>
... </div>
... """
>>> d = pq(data)
>>> print d('.xyz.tab')
<div class="xyz tab">test1</div>
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195