2024-10-03 06:26:25 发布
网友
我有一个xpath,可以在pythonscrapy和firefox的firebug扩展中使用。但是,它在python-selenium中不起作用。我在selenium中使用的代码是
xpath = ".//div[@id='containeriso3']/div/a[1]/@href" browser.find_element_by_xpath(xpath)
这将产生InvalidSelectorException错误。selenium是否使用其他xpath版本?在
这不会给你一个元素。您需要去掉@href属性。在
@href
使用.//div[@id='containeriso3']/div/a[1]
.//div[@id='containeriso3']/div/a[1]
然后使用get_attribute从中得到href。在
get_attribute
href
这不会给你一个元素。您需要去掉
@href
属性。在使用
.//div[@id='containeriso3']/div/a[1]
然后使用
get_attribute
从中得到href
。在相关问题 更多 >
编程相关推荐