爬虫 - 超级鹰的基本使用


# 一、超级鹰的使用步骤 ## 1.超级鹰 - 注册 - 登录 - 题分 - 创建软件(ID) - 下载示例代码

二、截取验证码的图片

  • 使用screenshot()保存截图
from time import sleep
from PIL import Image
from selenium import webdriver
from chaojiying_Python.chaojiying import Chaojiying_Client

# 创建浏览器对象


bro = webdriver.Chrome(executable_path='./chromedriver.exe')
bro.maximize_window()
bro.execute_script("document.body.style.zoom=0.8")
bro.get('https://kyfw.12306.cn/otn/resources/login.html')

# 获取账号和密码页面
a_data = bro.find_element_by_css_selector('.login-hd-account>a')
sleep(1)
# 点击账号和密码登录
a_data.click()
sleep(2)

# 获取验证码图片对应的标签信息
img_src = bro.find_element_by_xpath('//*[@id="J-loginImg"]').screenshot('code.png')
sleep(2)

三、使用动作链点击验证码

  • 切换参照物的作用域, 切换到验证码区域 : ActionChains(bro).move_to_element_with_offset(img_data, x, y).click().perform()
from time import sleep
from PIL import Image
from selenium import webdriver
from selenium.webdriver import ActionChains
from chaojiying_Python.chaojiying import Chaojiying_Client

# 创建浏览器对象
bro = webdriver.Chrome(executable_path='./chromedriver.exe')
# 最大化窗口
bro.maximize_window()
bro.get('https://kyfw.12306.cn/otn/resources/login.html')

# 获取账号和密码页面
a_data = bro.find_element_by_css_selector('.login-hd-account>a')
sleep(1)
# 点击账号和密码登录
a_data.click()
sleep(2)

# 获取验证码图片对应的标签信息
img_data = bro.find_element_by_xpath('//*[@id="J-loginImg"]')
img_src = bro.find_element_by_xpath('//*[@id="J-loginImg"]').screenshot('code.png')
sleep(2)

# 获取账号和密码框
username = bro.find_element_by_id('J-userName')
password = bro.find_element_by_id('J-password')
# 获取登录按钮
login_bt = bro.find_element_by_id('J-login')
username.send_keys('Fei19961028')
sleep(2)
password.send_keys('fei19961028')

#获取验证码
chaojiying = Chaojiying_Client('fei19961028', 'zhrmghgwswswws', '915658')  # 用户中心>>软件ID 生成一个替换 96001
im = open('code.png', 'rb').read()  # 本地图片文件路径 来替换 a.jpg 有时WIN系统须要//

str = chaojiying.PostPic(im, 9004)['pic_str']

all_list = []
if '|' in str:
    list_1 = str.split('|')
    print(list_1[0].split(',')[0])
    count_1 = len(list_1)
    for i in range(count_1):
        xy_list = []
        x = int(list_1[i].split(',')[0])
        y = int(list_1[i].split(',')[1])
        xy_list.append(x)
        xy_list.append(y)
        all_list.append(xy_list)
else:
    x = int(str.split(',')[0])
    y = int(str.split(',')[1])
    xy_list = []
    xy_list.append(x)
    xy_list.append(y)
    all_list.append(xy_list)

# 使用动作链点击验证码
for l in all_list:
    x = l[0]
    y = l[1]
    # 切换参照物的作用域
    ActionChains(bro).move_to_element_with_offset(img_data, x, y).click().perform()
sleep(2)
login_bt.click()
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值