I am following this build of a scraper for LinkedIn job data.
Here is my code:
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'))
I have seen this, and attempted the solution, but received a similar error, except with regards to the WebDriver object not having a driver attribute.
Here is the full error message:
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'
Okay, I answered my own question. The individual methods find_element_by_* have been replaced by find_element, e.g.
no_of_jobs = int(wd.find_element(By.CSS_SELECTOR, 'h1>span'))
More info is here
Selenium recently removed the 16 deprecated find_element(s)_by_x
functions in favor of a general find_element
and find_elements
function that take the "by" part as their first argument.
To update your code, you can use your IDE's find-and-replace-all feature to replace these 16 search terms:
.find_element_by_class_name(
.find_element(By.CLASS_NAME,
.find_element_by_css_selector(
.find_element(By.CSS_SELECTOR,
.find_element_by_id(
.find_element(By.ID,
.find_element_by_link_text(
.find_element(By.LINK_TEXT,
.find_element_by_name(
.find_element(By.NAME,
.find_element_by_partial_link_text(
.find_element(By.PARTIAL_LINK_TEXT,
.find_element_by_tag_name(
.find_element(By.TAG_NAME,
.find_element_by_xpath(
.find_element(By.XPATH,
.find_elements_by_class_name(
.find_elements(By.CLASS_NAME,
.find_elements_by_css_selector(
.find_elements(By.CSS_SELECTOR,
.find_elements_by_id(
.find_elements(By.ID,
.find_elements_by_link_text(
.find_elements(By.LINK_TEXT,
.find_elements_by_name(
.find_elements(By.NAME,
.find_elements_by_partial_link_text(
.find_elements(By.PARTIAL_LINK_TEXT,
.find_elements_by_tag_name(
.find_elements(By.TAG_NAME,
.find_elements_by_xpath(
.find_elements(By.XPATH,
You'll also need to import By
if you haven't already done so:
from selenium.webdriver.common.by import By
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With