3 ms·
Or you could use lxml in Python, which allows you to mix XPath and CSS Selectors. E.g.: from lxml import html doc = html.fromstring('<html><body><p class=
by pyre 13y ago
Or you could use lxml in Python, which allows you to mix XPath and CSS Selectors. E.g.:
from lxml import html
doc = html.fromstring('<html><body><p class="text"></p></body></html>')
doc.xpath('//p[@class = "text"]') == doc.cssselect('p.text')
# or
doc = html.fromstring('<html><body><p>1</p><p>2</p><p>3</p></body></html>')
doc.xpath('//p[2]')[0] == doc.cssselect('p')[1]
# Note: My only annoyance is that .xpath() always returns a list, even
# when you know that it will return only a single item.