在用selenium时,发现用@href拿不到标签的属性,但是去掉@href时不报错,发现不是代码的问题,才发现原来selenium有专门的获取方式
这是我第一次的代码(至于为什么这么写,是因为requests中这样可以获取到href的属性),很遗憾它报错啦
detail_url = element.find_element_by_xpath(".//a/@href")
接着我又把@href去掉,并没有报错,我发现可能是我用requests中的方法是不对的
detail_url = element.find_element_by_xpath(".//a")
然后我就去网上查阅资料,发现selenium使用这种方法来实现属性的获取的
detail_url = element.find_element_by_xpath(".//a").get_attribute("href")
在这里写给大家,希望大家可以看得到,用得上