我正在尝试使用解析 HTML
a = lxml.html.fromstring('<html><body><span class="cut cross">Text of double class</span><span class="cross">Text of single class</span></body></html>')
s1 = a.xpath('.//span[@class="cross"]')
s2 = a.xpath('.//span[@class="cut cross"]')
s3 = a.xpath('.//span[@class="cut"]')
输出:
s1 => [<Element span at 0x7f0a6807a530>]
s2 => [<Element span at 0x7f0a6807a590>]
s3 => []
但是第一个 span 标签的类是“cut”,但 s3 是空的。在 s2 中,当我同时给出两个类时,它会返回标签。