3 ms·
CSS selectors don't have to select purely by classes. They can be something like: div > div > * > *:nth-child(7) XPath doesn't have any additional abilities,
by goldenkey 4y ago
CSS selectors don't have to select purely by classes. They can be something like:
div > div > * > *:nth-child(7)
XPath doesn't have any additional abilities, it's just verbose and difficult to write. It's a lemon.
- chrismeller 4y agoWell that is 100% originally an XPath selector (:nth-child), so kudos if CSS selectors support it now. Still, using // instead of multiple *’s (and the two divs) still seems better for longer-term scraping.
- tommica 4y agoI might be wrong, but xpath has contains, where you can look for a text content inside an element, which I don't think CSS can do
- mdaniel 4y agoYeah, for sure XPath is the more powerful of the two, so much so that Scrapy's parsel library parses CSS selectors and transforms then into the equivalent XPath for execution To the best of my knowledge, CSS selectors care only about the structure of the page, lightly dipping its toes in the content only for attributes and things like :first-char and :first-line