相关疑难解决方法(0)

Selenium AttributeError:“WebDriver”对象没有属性“find_element_by_css_selector”

我正在关注这个LinkedIn 职位数据抓取工具的构建。

这是我的代码:

from selenium import webdriver
import time
import pandas as pd

url = 'https://www.linkedin.com/jobs/search?keywords=&location=San%20Francisco%2C%20California%2C%20United%20States&locationId=&geoId=102277331&f_TPR=&distance=100&position=1&pageNum=0'

wd = webdriver.Chrome(executable_path=r'/Users/voi/chromedriver')
wd.get(url)

no_of_jobs = int(wd.driver.find_element_by_css_selector('h1>span').get_attribute('innerText'))
Run Code Online (Sandbox Code Playgroud)

我已经看到了这个,并尝试了解决方案,但收到了类似的错误,除了关于没有驱动程序属性的 WebDriver 对象。

这是完整的错误消息:

cd /Users/voi ; /usr/bin/env /usr/local/bin/python3 /Users/voi/.vscode/extensions/ms-python.python-2
022.8.1/pythonFiles/lib/python/debugpy/launcher 59402 -- /Users/voi/jobscrape.py 
/Users/voi/jobscrape.py:7: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
  wd = webdriver.Chrome(executable_path=r'/Users/voi/chromedriver')
Traceback (most recent call last):
  File "/Users/voi/jobscrape.py", line 10, in <module>
    no_of_jobs = int(wd.find_element_by_css_selector('h1>span').get_attribute('innerText'))
AttributeError: 'WebDriver' object has no attribute 'find_element_by_css_selector'
Run Code Online (Sandbox Code Playgroud)

python selenium selenium-webdriver

15
推荐指数
2
解决办法
5万
查看次数

Selenium WebDriver访问子元素

我有一个div唯一的ID.在那之下div有一堆span元素className=foo.有几个span元素,className=foo但每个元素都是独一无二的div(如果清楚的话).所以,我的硒代码首先获取独特div的网络元素,然后尝试采取元素和类的名称得到span像这样

element = sDriver.findElement(By.id("c_"+cID)); 
String sTest = element.findElement(By.className("actions")).getText();
Run Code Online (Sandbox Code Playgroud)

在第二行,它每次都抛出一个异常

org.openqa.selenium.StaleElementReferenceException: Element not found in the cache - perhaps the page has changed since it was looked up
Command duration or timeout: 22 milliseconds
Run Code Online (Sandbox Code Playgroud)

我是否误解了如何span从一个独特的东西中获得它div

selenium webdriver selenium-webdriver

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

selenium ×2

selenium-webdriver ×2

python ×1

webdriver ×1