'Why I can't find any selector with Xpath using two classes
I got a html page like this
<li class="class1 class2"></li>
but I try to find this selector by using
response.xpath('//li[@class="class1 class2"]')
I always got None. I also try to run this code:
response.xpath('//li[@class="class1"]')
response.xpath('//li[@class="class1 class2"]')
Both return None
Who can tell me what's wrong?
Maybe I resolved but I don't understand. I found a phenomenon that I use DevTools on Chrome, that shows like this <li class="class1 class2"><\li>. But I use scrapy to crawl and return <li class="class1 class2 class3"><\li>
I encountered some phenomenon that the web page source code is different from the source code I crawled.
Solution 1:[1]
Main issue is your <li><\li> is not valid HTML like <li></li> and xpath should look like:
.//li[contains(@class, 'class1') and contains(@class, 'class2')]
May use a tool like xpather to check if a path works or not.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | HedgeHog |
