webdriver.chrome 没有给我executable_path 作为参数,这可能是错误的

问题描述 投票:0回答:1

尝试从网站上取消作业并通过 class_name 定位元素获得了类名称,但当我运行代码时,我的控制台上没有显示任何内容

from selenium import webdriver
import  time
import pandas as pd
import os   

from selenium.webdriver.support.select import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC


website = "https://vanhack.com/jobs"
driver_path = "/Users/Backdoor/Desktop/12projects/vanhack/chromedriver.exe"
browser = webdriver.ChromeService(executable_path=driver_path)
driver = webdriver.Chrome(service=browser)


content = driver.find_element(By.CLASS_NAME, 'lline-number')
selenium-webdriver
1个回答
0
投票

您的代码甚至不使用

website
变量。您可以尝试使用这些代码来获取您想要的内容:

from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.common.exceptions import WebDriverException

website = "https://vanhack.com/jobs"
options = Options()
# you can optionally use headless mode via the options
driver = webdriver.Chrome(service=Service(), options=options)
driver.get(website)
html = driver.page_source
driver.quit()

soup = BeautifulSoup(html, features='html.parser')
content = soup.find('div', class='lline-number')
© www.soinside.com 2019 - 2024. All rights reserved.