首页 > 解决方案 > 预期的 str、bytes 或 os.PathLike 对象,而不是元组

问题描述

在尝试打开 chrome 窗口然后将其转到 instagram.com 时,我不断收到预期的 str、字节或 os.PathLike 对象,而不是元组。我正在通过创建一个机器人来练习 python,并且很好奇它为什么会给我这个错误,任何帮助都将不胜感激。编译器将错误定位在“self.driver = webdriver.Chrome(ChromeDriverDownloader().download_and_install())”的代码行上

from selenium import webdriver
from webdriverdownloader import ChromeDriverDownloader
import os
import time

class InstagramBot:

    #Does this code when program is ran
    def __init__(self, username, password):
        #Creates username and password of user
        self.username = username
        self.password = password

        #Opens chrome driver which opens chrome
        self.driver = webdriver.Chrome(ChromeDriverDownloader().download_and_install())

        self.driver.get('https://www.instagram.com/')


if __name__ == '__main__':
    ig_bot = InstagramBot('temp_username', 'temp_password')

标签: python

解决方案


ChromeDriverDownloader().download_and_install()返回一个元组。

文档

def download_and_install(self, version="latest", os_name=None, bitness=None, show_progress_bar=True):
    """
    Method for downloading a web driver binary, extracting it into the download directory and creating a symlink
    to the binary in the link directory.
    :param version: String representing the version of the web driver binary to download.  For example, "2.38".
                    Default if no version is specified is "latest".  The version string should match the version
                    as specified on the download page of the webdriver binary.
    :param os_name: Name of the OS to download the web driver binary for, as a str.  If not specified, we will use
                    platform.system() to get the OS.
    :param bitness: Bitness of the web driver binary to download, as a str e.g. "32", "64".  If not specified, we
                    will try to guess the bitness by using util.get_architecture_bitness().
    :param show_progress_bar: Boolean (default=True) indicating if a progress bar should be shown in the console.
    :returns: Tuple containing the path + filename to [0] the extracted binary, and [1] the symlink to the
              extracted binary.

推荐阅读