selenium中xpath爬虫语法问题
title = driver.find_elements_by_xpath('//div[@class="top"]/p/text()')以前是这么写的,现在这么写会报错。AttributeError: 'WebDriver' object has no attribute 'find_element_by_xpath'。
是语句写法改变了吗 https://blog.csdn.net/m0_52818006/article/details/126283288 selenium版本更新以后有些方法不能用了,改成以下代码:
from selenium.webdriver.common.by import By
title = driver.find_elements(By.XPATH, r'//div[@class="top"]/p/text()')
lxping 发表于 2022-12-20 11:26
selenium版本更新以后有些方法不能用了,改成以下代码:
InvalidSelectorException: invalid selector: The result of the xpath expression "//div[@class="top"]//text()" is: . It should be an element.
不能直接指向文本吗? 937135952 发表于 2022-12-20 11:34
InvalidSelectorException: invalid selector: The result of the xpath expression "//div[@class="top" ...
是的,参考这个吧https://www.5axxw.com/questions/content/7r2nrl 已解决,标记一下写法 title = driver.find_elements(By.XPATH, r'//div[@class="top"]/p').text
页:
[1]