当前位置: 首页 > 知识库问答 >
问题:

Selenium Python登录Instagram的几个问题

孔华池
2023-03-14

这是错误:

回溯(最近调用最后):html" target="_blank">文件“C://users/anton/desktople/instabot/chrome instagram bot/main.py”,第8行,在my_driver.sign_in(username=username,password=password)文件“C:\users\anton\desktople\instabot\chrome instagram bot\chrome_driver_cli.py”,第39行,在sign_in username_input=self.driver.find_element_by_name(“username”)文件“d_element_by_name返回self.find_element(by=by.name,value=name)文件”C:\users\anton\desktop\instabot\chrome instagram bot\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py“,第978行,在find_element'value':value}中)['value']文件”C:\users\anton\desktop\instabot\chrome instagram RAM bot\venv\lib\site-packages\selenium\webdrIver\remote\errorhandler.py“,第242行,在check_response引发exception_class(message,screen,stacktrace)selenium.common.exceptions.nosuchelementexception:message:没有这样的元素:找不到元素:{”method“:”CSS selector“,”selector“:”[name=“username”]“}(会话信息:chrome=79.0.3945.130)

这是密码

from selenium import webdriver
from selenium.common.exceptions import SessionNotCreatedException
from selenium.webdriver.common.keys import Keys


supported_versions_path = [
            "..\\chrome driver\\CHROME 80\\chromedriver.exe",
            "..\\chrome driver\\CHROME 79\\chromedriver.exe",
            "..\\chrome driver\\CHROME 78\\chromedriver.exe"
        ]

instagram_link = "https://www.instagram.com/accounts/login/?source=auth_switcher"


class ChromeDriver:

    def __init__(self):
        self.driver = self.__startup()


    def __startup(self):

        self.driver = None
        for current_checking_version in supported_versions_path:
            if self.driver is None:
                try:
                    self.driver = webdriver.Chrome(current_checking_version)
                    pass
                except SessionNotCreatedException:
                    self.driver = None
        return self.driver

    def sign_in(self, username, password):

        self.driver.get(instagram_link)
        frame = self.driver.find_element_by_tag_name("iframe")
        self.driver.switch_to.frame(frame)

        username_input = self.driver.find_element_by_name("username")
        # password_input = self.driver.find_element_by_name('password')
        # username_input.send_keys(username)
        # password_input.send_keys(password)
        # password_input.send_keys(Keys.ENTER)

    def get_page(self, url):
        self.driver.get(url)

    def quit(self):
        self.driver.quit()

你能帮我吗?

共有1个答案

田信然
2023-03-14

看来你们很亲密。Instagram上的username字段是一个ReactJS,因此您必须诱导WebDriverWait,然后使用以下任何一种定位器策略调用send_keys():

>

  • CSS_Selector:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[name='username']"))).send_keys("Antonio_Sabatino")
    

    XPath:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@name='username']"))).send_keys("Antonio_Sabatino")
    
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    

  •  类似资料:
    • 我做了一个代码,尝试登录我的instagram账户,但它给了我很多错误。我怎样才能修好它们? 代码: 错误: 警告(来自警告模块):文件“C:\users\usuario\appdata\local\programs\python\python37\lib\site-packages\Selenium\webdriver\PhantomJS\webdriver.py”,第49行warnings.w

    • 我想实现Instagram登录。但当我安装react native instagram登录npm并放置此代码时 并运行此代码,得到一个错误-1。不变违规:当instagram登录反应本机2时,尝试注册两个同名的RNCWebview视图。模块应用注册表未注册可调用模块(调用runApplication) 如何改掉这个错误package.json },

    • 问题内容: 我正在使用OpenID。我如何做到使用户即使关闭浏览器窗口也能长时间保持登录状态? 如何存储和访问用户的对象? 基本上,我想我只是不太了解会话如何在Java中工作。 问题答案: 因此,你实际上想要一个“在此计算机上记住我”选项吗?这实际上与OpenID部分无关。这是一种与语言无关的方式: 首先创建至少包含和列的数据库表。如有必要,还添加和。我猜这些列名不言而喻。 在第一次登录(如果必要

    • 我正在构建angular2应用程序,目前我有一个家庭组件与菜单栏和路由器出口的主要内容。我添加了登录机制,所以如果用户没有经过身份验证,那么登录页面将显示在整个屏幕上,登录后用户将被路由到上面结构的主/主组件。 当我运行登录页面加载的应用程序时,成功验证后,它会将我路由到主页,但在加载菜单的主页(如Dashboard1、Dashboard2、Report1等)中,链接无法正常工作。当我点击任何菜单

    • 我可以通过重新启动服务器并尝试重新登录来重现此问题。我在开发模式和生产模式中测试了这个问题,得到了相同的行为。

    • 对于一个练习,我尝试创建一个登录页面。这是我第一次使用php。我已经看过很多指南,也看过stackoverflow的很多问题。这就是我想到的。(我正在对数据库使用XAMPP) 文件夹php:login。php,会话。欢迎。php,连接。php 文件夹页面:登录。html DB名称:leftoveryouth 表名:客户端 Colums:id、名、姓、出生日期、街道、街道、城市、plz、用户名、电子