# -*- coding: utf-8 -*-
import time
import sys
import os
from selenium.webdriver import ActionChains
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.keys import Keys
# myusername = "XXX"#登录账号
# mypassword = "XXX"#登录密码
#打开文件
name_list = open('d:\\user_pass.txt','r+')
#读取该文件行数count
count=len(open(r"d:\\user_pass.txt",'r').readlines())
print("该文件行数",count)
# 打开记录用户名密码的文本,文本内格式为:test:test
name_text = dict(line.strip().split(":") for line in name_list if line)
print(name_text)
# 将每行分别读取并作为字典
u = list(name_text.keys())
p = list(name_text.values())
driver = webdriver.Firefox() # 模拟浏览器打开网站
for count in range(count):
username = u[count]
password = p[count]
print(username)
print(password)
count=count+1
print("---------------------------")
time.sleep(2)
driver.get("http://pj.maigi.cn:8001")
# 找到登录框,输入账号密码
driver.find_element_by_xpath("//*[@placeholder='手机号']").send_keys(username)
driver.find_element_by_xpath("//*[@placeholder='密码']").send_keys(password)
time.sleep(2)
# 模拟点击登录
driver.find_element_by_xpath("//*[@class='loginBt1']").click()
time.sleep(2)
print("登陆完毕")
driver.get("http://pj.maigi.cn:8001/Account/LogOffReturn")
#切换窗口
driver.quit # 退出去动
Python读取文件账号密码信息批量登录网址
最新推荐文章于 2024-06-18 11:04:37 发布
本文介绍使用Python和Selenium库实现自动化登录pj.maigi.cn网站的过程,并展示了如何遍历用户名和密码列表进行批量登录。通过ActionChains模拟真实用户行为,适合测试和脚本自动化任务。
911

被折叠的 条评论
为什么被折叠?



