首页 > 解决方案 > github 在每个 selenium-webdriver 测试中要求验证码

问题描述

每当我尝试运行我的 python 脚本时,我都会尝试使用 selenium-webdriver 登录 Github每次验证我的验证码。我的代码有问题吗?这是我的代码:

from selenium import webdriver
from importlib import reload
import time
import sys

reload(sys)


# Firefox used
driver = webdriver.Chrome()
# base url
driver.get("http://github.com/login")

username = driver.find_element_by_id("login_field")
password = driver.find_element_by_id("password")

# password and username need to go into these values
username.send_keys("username")
time.sleep(1)
password.send_keys("password")
time.sleep(1)

login_form = driver.find_element_by_xpath("//input[@value='Sign in']")
time.sleep(1)
login_form.click()
time.sleep(1)

# These are some of the most popular users on github
prepend = ["jashkenas", "ruanyf", "substack", "kennethreitz", "jlord", "daimajia", "mdo", "schacon", "mattt",
           "sindresorhus", "defunkt", "douglascrockford", "mbostock", "jeresig",
           "mojombo", "addyosmani", "paulirish", "vczh", "romannurik", "tenderlove", "chriscoyier", "johnpapa",
           "josevalim",
           "charliesome", "CoderMJLee", "ry", "antirez", "muan", "isaacs", "angusshire",
           "hadley", "hakimel", "yyx990803", "fat", "fabpot", "ibireme", "tekkub",
           "BYVoid", "laruence", "onevcat", "tpope", "mrdoob", "LeaVerou", "chrisbanes", "wycats", "lifesinger",
           "cloudwu", "mitsuhiko", "michaelliao", "ryanb", "clowwindy", "JacksonTian", "yinwang0", "Trinea",
           "pjhyett", "dhh", "gaearon"]

for user in prepend:
    for t in range(1, 100):

        string = "https://github.com/{}/followers?page={}".format(user, t)
        driver.get(string)
        time.sleep(1)

        # make sure to pick the correct directory to save the files to
        # follow_button = driver.find_elements_by_xpath("//button[@type='submit']")
        follow_button = driver.find_elements_by_xpath("//button[@aria-label='Follow this person']")

        # Once page is loaded this clicks all buttons for follow
        try:
            for i in follow_button:
                i.submit()
        except:
            pass
        time.sleep(1)

driver.close()

标签: seleniumselenium-webdrivergithubselenium-chromedriver

解决方案


推荐阅读