【问题标题】:expected str, bytes or os.PathLike object, not tuple预期的 str、bytes 或 os.PathLike 对象,而不是元组
【发布时间】:2020-03-27 19:28:57
【问题描述】:

尝试打开 chrome 窗口然后将其转到 instagram.com 时,我不断收到预期的 str、bytes 或 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


    【解决方案1】:

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

    来自documentation

    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.
    

    【讨论】:

    • 那么您建议如何解决它?我对 python 比较陌生
    • 您需要从元组中提取其中一个值并使用它。您需要哪个值是您需要确定的。可以像访问数组中的值一样访问元组的值,使用 myTuple[<index>]
    猜你喜欢
    • 2018-11-08
    • 2018-11-11
    • 2022-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-24
    相关资源
    最近更新 更多