是否可以进行类似的操作(仅使用xpath):
filtered = response.xpath('//input[@type="submit"]')
filtered.xpath('[contains(@name, "abc")]')
上面的代码产生异常:
ValueError:XPath错误:[包含(@name, “ abc”)]
答案 0 :(得分:1)
您可以选择最初正确的元素:
filtered = response.xpath('//input[@type="submit"][contains(@name, "abc")]')
或过滤如下
filtered = response.xpath('//input[@type="submit"]')
# by exact @name value
new_filtered = [item for item in filtered if item.attrib['name'] == 'abc']
# by partial @name value
new_filtered = [item for item in filtered if 'abc' in item.attrib['name']]