[Python] Used webdriver.ChromeService to save path as a service, but os.path.expanduser...

Discussão em 'Python' iniciado por Stack, Maio 18, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to scrape a real estate website, but I'm getting an error early in the process.

    Here's the problematic code:

    chromedriver = webdriver.ChromeService(executable_path=r"D:/My Download/chromedriver_win32/chromedriver.exe")
    chromedriver = os.path.expanduser(chromedriver)
    print('chromedriver path: {}'.format(chromedriver))
    sys.path.append(chromedriver)
    driver = webdriver.Chrome(chromedriver)


    Here's the error:

    TypeError
    Traceback (most recent call last)
    Cell In\[8\], line 2
    1 chromedriver = webdriver.ChromeService(executable_path=r"D:/My Download/chromedriver_win32/chromedriver.exe") # path to the chromedriver executable
    2 chromedriver = os.path.expanduser(chromedriver)
    3 print('chromedriver path: {}'.format(chromedriver))
    4 sys.path.append(chromedriver)

    File \<frozen ntpath\>:347, in expanduser(path)

    TypeError: expected str, bytes or os.PathLike object, not Service


    I tried to re-write the path in several different ways including single quotes, double quotes, with r, without r, but nothing has worked.

    Continue reading...

Compartilhe esta Página