XPath在scrapy中工作但不在硒中工作

时间:2013-02-06 11:24:03

标签: python selenium scrapy xpath

我有一个xpath,它可以在python-scrapy中运行,也可以在firefox的firebug扩展中运行。但是,它不适用于python-selenium。我在selenium中使用的代码就是这个

xpath = ".//div[@id='containeriso3']/div/a[1]/@href"
browser.find_element_by_xpath(xpath)

这会产生InvalidSelectorException错误。 selenium是否使用其他一些xpath版本?

1 个答案:

答案 0 :(得分:3)

这不会让你成为一个元素。您需要关闭@href属性。

使用.//div[@id='containeriso3']/div/a[1]

然后使用get_attribute从中获取href