Ошибка Python Selenium ChromeDriver? WebDriver.__init__() получил неожиданный аргумент ключевого слова «executable_path»Python

Программы на Python
Ответить
Anonymous
 Ошибка Python Selenium ChromeDriver? WebDriver.__init__() получил неожиданный аргумент ключевого слова «executable_path»

Сообщение Anonymous »

Итак, я новичок в программировании и должен анализировать обзоры Yelp, чтобы иметь возможность анализировать данные с помощью Pandas. Я пытаюсь использовать selenium/beautifulsoup для автоматизации всего процесса, но не могу обойти ошибки webdriver/chromedriver в каждой версии кода, который я создаю.

Код: Выделить всё

!pip install selenium
from selenium import webdriver
from bs4 import BeautifulSoup
import pandas as pd
import os

# Set the path to the ChromeDriver executable
chromedriver_path = "C:\\Users\\5mxz2\\Downloads\\chromedriver\\chromedriver"

# Set the URL of the Yelp page you want to scrape
url = "https://www.yelp.com/biz/gelati-celesti-virginia-beach-2"

# Set the options for Chrome
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--headless")  # Run Chrome in headless mode, comment this line if you want to see the browser window

# Create the ChromeDriver instance
driver = webdriver.Chrome(executable_path=chromedriver_path, options=chrome_options)

# Load the Yelp page
driver.get(url)

# Extract the page source and pass it to BeautifulSoup
soup = BeautifulSoup(driver.page_source, "html.parser")

# Find all review elements on the page
reviews = soup.find_all("div", class_="review")

# Create empty lists to store the extracted data
review_texts = []
ratings = []
dates = []

# Iterate over each review element
for review in reviews:
# Extract the review text
review_text = review.find("p", class_="comment").get_text()
review_texts.append(review_text.strip())

# Extract the rating
rating = review.find("div", class_="rating").get("aria-label")
ratings.append(rating)

# Extract the date
date = review.find("span", class_="rating-qualifier").get_text()
dates.append(date.strip())

# Create a DataFrame from the extracted data
data = {
"Review Text": review_texts,
"Rating": ratings,
"Date": dates
}
df = pd.DataFrame(data)

# Print the DataFrame
print(df)

# Get the current working directory
path = os.getcwd()

# Save the DataFrame as a CSV file
csv_path = os.path.join(path, "yelp_reviews.csv")
df.to_csv(csv_path, index=False)

# Close the ChromeDriver instance
driver.quit()

Это то, что у меня есть до сих пор, но я продолжаю получать это сообщение об ошибке

Код: Выделить всё

TypeError                                 Traceback (most recent call last)
 in ()
16
17 # Create the ChromeDriver instance
---> 18 driver = webdriver.Chrome(executable_path=chromedriver_path, options=chrome_options)
19
20 # Load the Yelp page

TypeError: WebDriver.__init__() got an unexpected keyword argument 'executable_path'
Может кто-нибудь помочь мне это исправить? А если у кого-то есть какие-либо советы по задаче в целом, дайте знать.

Подробнее здесь: https://stackoverflow.com/questions/765 ... cted-keywo
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»