试着去理解为什么我总是出现这个错误

2024-07-04 15:51:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在看一段关于selenium I python的freecodecamp视频,他使用的这个方法对我不起作用,我也不明白为什么

class Booking(webdriver.Chrome):
    def __init__(self, driver_path=r"C:\SeleniumDrivers"):
       self.driver_path = driver_path
       os.environ['PATH'] += self.driver_path
       super(Booking, self).__init__()

    def land_first_page(self):
       self.get('https://www.booking.com')

Tags: path方法self视频initosdefdriver
1条回答
网友
1楼 · 发布于 2024-07-04 15:51:31

我不确定您是否错过了代码或在视频中错过了-此代码中缺少路径分隔符。因此,当加入路径时,路径分隔符需要存在(例如>;:对于mac和;对于windows),请参考代码中的注释

from selenium import webdriver
import os
class Booking(webdriver.Chrome):
    def __init__(self, driver_path=r"C:\SeleniumDrivers"):
       self.driver_path = driver_path
       os.environ['PATH'] +=  os.pathsep + self.driver_path # os.pathsep is missing,i.e add chromedriver path the system path.
       super(Booking, self).__init__()

    def land_first_page(self):
       self.get('https://www.booking.com')

还要确保chromedriver已下载并复制到C:\SeleniumDrivers

相关问题 更多 >

    热门问题