selenium - 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()
解决方案
推荐阅读
- java - 在不知道值键的情况下读取孩子的值
- javascript - 从对象 VUE 向 fullcalendar 添加事件
- excel - 如何通过 VBA 点击网页上的链接
- java - 我尝试将 android 项目与产生错误的 firebase 连接
- python - 在 pandas.DataFrame 中将列转换为标题
- epicorerp - BPM ABL 查询输出到 CSV 文件 - 示例
- ruby-on-rails - 为什么 AWS 上传文字文件路径,而不是上传图片?
- python-3.x - 转置列和数据引导
- python - 将 mediapipe iris tflite 转换为 tf/keras 作为预处理器
- jena - 如何用通用规则引擎中的内置 listContains 替换 SPARQL 中的 VALUES