import requests
from selenium import webdriver
import os
import time
from selenium.webdriver.common.by import By
import urllib.request # 这里修正一处拼写错误,原代码中 urlretrieve 所在模块引入有误,应该是 urllib.request
from io import BytesIO
import chaojiying
from chaojiying import Chaojiying_Client # 从chaojiying模块中导入Chaojiying类

https://www.chaojiying.com/

创建驱动对象(Edge),需要注意要配置好Edge驱动(EdgeDriver),并且确保其路径正确添加到系统环境变量PATH中

driver = webdriver.Edge()

加载网址

driver.get(‘https://www.chaojiying.com/’)

窗口最大化

driver.maximize_window()
time.sleep(0.5)
driver.find_element(By.ID, ‘login-register’).click()
time.sleep(1)

通过ID定位用户名输入框(这里假设用户名输入框的id是’username’,需根据实际页面调整)

username_input = driver.find_element(By.ID, ‘user’)
username_input.click()
username_input.send_keys(‘ye17876586815’)
time.sleep(1)

通过ID定位密码输入框(你代码中已写了对应的id为’pass’,这里再次明确下规范写法)

password_input = driver.find_element(By.ID, ‘pass’)
password_input.click()
password_input.send_keys(‘ye17876586815’)
time.sleep(1)

img=driver.find_element(By.XPATH,‘//div[@class=“col-xs-12 auth”]/img’)

img.screenshot(‘img.png’)

time.sleep(0.5)

然后实例化类并使用,传入相应参数

chaojiying_obj = Chaojiying_Client(‘ye17876586815’, ‘ye17876586815’, ‘967063’)
im=open(‘img.png’,‘rb’).read()
img_bytes = img.screenshot_as_png # 获取图片的字节流数据,无需保存为本地文件 # 获取验证码图片字节流数据,前面代码示例中有相关逻辑
yzm = chaojiying_obj.PostPic(BytesIO(img_bytes), 1004)[‘pic_str’]
time.sleep(1)

driver.find_element(By.ID,‘auth’).send_keys(yzm)

time.sleep(1)

driver.find_element(By.CLASS_NAME,‘common-login-btn’).click()

time.sleep(2)

print(dir(chaojiying))

# 最后记得关闭浏览器驱动,释放相关资源

driver.quit()

Logo

GitCode 天启AI是一款由 GitCode 团队打造的智能助手,基于先进的LLM(大语言模型)与多智能体 Agent 技术构建,致力于为用户提供高效、智能、多模态的创作与开发支持。它不仅支持自然语言对话,还具备处理文件、生成 PPT、撰写分析报告、开发 Web 应用等多项能力,真正做到“一句话,让 Al帮你完成复杂任务”。

更多推荐