# 下面是12306 实现的模拟登陆

# 解码 应用超级鹰,注册用户,左侧栏软件ID进去,开启一个新软件,拿到软件ID

# 下面测试都在jupyter里面实现

# 超级鹰类 cell

import requests

from hashlib import md5

class Chaojiying_Client(object):

def __init__(self, username, password, soft_id):

self.username = username

password = password.encode(‘utf8‘)

self.password = md5(password).hexdigest()

self.soft_id = soft_id

self.base_params = {

‘user‘: self.username,

‘pass2‘: self.password,

‘softid‘: self.soft_id,

}

self.headers = {

‘Connection‘: ‘Keep-Alive‘,

‘User-Agent‘: ‘Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)‘,

}

def PostPic(self, im, codetype):

params = {

‘codetype‘: codetype,

}

params.update(self.base_params)

files = {‘userfile‘: (‘ccc.jpg‘, im)}

r = requests.post(‘http://upload.chaojiying.net/Upload/Processing.php‘, data=params, files=files, headers=self.headers)

print(r.json()) #{‘err_no‘: 0, ‘err_str‘: ‘OK‘, ‘pic_id‘: ‘9067216592371000003‘, ‘pic_str‘: ‘24,62|40,146|112,141‘, ‘md5‘: ‘c4ee4d4fb269521c47de228d5c6d6d3e‘}

return r.json()

def ReportError(self, im_id):

params = {

‘id‘: im_id,

}

params.update(self.base_params)

r = requests.post(‘http://upload.chaojiying.net/Upload/ReportError.php‘, data=params, headers=self.headers)

return r.json()

# 下面是12306 页面的处理

from selenium importwebdriverimporttimeimportrequestsfrom lxml importetreefrom urllib importrequestfrom selenium.webdriver.common.action_chains importActionChainsfrom PIL importImage

bro= webdriver.Chrome(executable_path=‘./chromedriver.exe‘)

bro.get(‘https://kyfw.12306.cn/otn/login/init‘)#page_text = bro.page_source#tree = etree.HTML(page_text)#code_img_src = tree.xpath(‘//*[@id="loginForm"]/div/ul[2]/li[4]/div/div/div[3][email protected])[0]#print(code_img_src)#request.urlretrieve(url=code_img_src,filename=‘./code.jpg‘)

time.sleep(3)

code_img_ele= bro.find_element_by_xpath(‘//*[@id="loginForm"]/div/ul[2]/li[4]/div/div/div[3]/img‘) #找见验证码区域

time.sleep(3)

location= code_img_ele.location #x,y

print(‘--‘,location) #-- {‘x‘: 274, ‘y‘: 274}

size =code_img_ele.sizeprint(‘++‘,location) #++ {‘x‘: 274, ‘y‘: 274}

rangle = (int(location[‘x‘]),int(location[‘y‘]),int(location[‘x‘]+size[‘width‘]),int(location[‘y‘]+size[‘height‘]))print(‘**‘,rangle)

bro.save_screenshot(‘aa.png‘) #快照

i = Image.open(‘./aa.png‘)

code_img_name= ‘code.png‘frame= i.crop(rangle) #裁剪

frame.save(code_img_name)

chaojiying= Chaojiying_Client(‘超级鹰账号‘, ‘超级鹰密码‘, ‘软件ID‘)#超级鹰用户中心>>软件ID 生成一个替换上

im = open(‘./code.png‘,‘rb‘).read()

result= chaojiying.PostPic(im, 9004)[‘pic_str‘]

all_list=[]if ‘|‘ inresult:

list_1= result.split(‘|‘)

count_1=len(list_1)for i inrange(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(result.split(‘,‘)[0])print(x)

y= int(result.split(‘,‘)[1])

xy_list=[]

xy_list.append(x)

xy_list.append(y)

all_list.append(xy_list)print(all_list) #[[24, 62], [40, 146], [112, 141]] 坐标位置

code_img = bro.find_element_by_xpath(‘//*[@id="loginForm"]/div/ul[2]/li[4]/div/div/div[3]/img‘)

action=ActionChains(bro)for l inall_list:

x=l[0]

y= l[1]

ActionChains(bro).move_to_element_with_offset(code_img,x,y).click().perform()

bro.find_element_by_id(‘username‘).send_keys(‘‘) #12306账号

time.sleep(2)

bro.find_element_by_id(‘password‘).send_keys(‘‘) #12306密码

time.sleep(2)

bro.find_element_by_id(‘loginSub‘).click()

time.sleep(10)

bro.quit()#退出

原文:https://www.cnblogs.com/zhangchen-sx/p/10826837.html

php selenium模拟登陆,12306 的selenium实现模拟登陆相关推荐

  1. 模拟登录12306(selenium+超级鹰)

    最近迷上了用selenium去登陆各大网站,别说selenium真挺好用,可以轻松搞定ajax动态加载的网页,不用很费劲的去抓包查找.咳咳-跑题了,回归正题. 这次用selenium去登录12306网 ...

  2. 以selenium模拟登陆12306

    初级模拟,速度有点慢,后期有时间再优化 1 # -*- coding:utf-8 -*- 2 # author:zxy 3 # date:2018-12-23 4 5 from selenium im ...

  3. selenium模拟登录12306

    利用selenium模拟登录12306,但是12306的登陆要想模拟还挺难的,需要先进行坐标识别,识别出来之后还要在进行滑块拖动验证识别,这里做一下记录. 这里的坐标识别是用的超级鹰,有时也会坐标识别 ...

  4. Python使用selenium模块模拟登录12306

    selenium模块概述 selenium模块是基于浏览器自动化的一个模块.换句话说使用selenium可以让浏览器根据自己写的代码自动运行. 相应的语法 ·编写基于浏览器自动化的操作代码 · 发起请 ...

  5. python爬虫登录12306失败_Python网络爬虫(selenium模拟登录12306网站)

    一.通过selenium自动登录12306官网 1.1 超级鹰打码平台API,创建chaojiyin.py文件 #!/usr/bin/env python#coding:utf-8 importreq ...

  6. Python3 爬虫实战 — 模拟登陆12306【点触验证码对抗】

    登陆时间:2019-10-21 实现难度:★★★☆☆☆ 请求链接:https://kyfw.12306.cn/otn/resources/login.html 实现目标:模拟登陆中国铁路12306,攻 ...

  7. Python爬虫学习笔记-第十二+十三课(selenium综合练习-12306购票)

    selenium综合练习-实现12306购票 1. 练习初衷 2. selenium实现12306购票 2.1 类基本框架 2.2 网站登录 2.3 车次以及余票查询 2.4 解析车次列表 2.5 确 ...

  8. Python + selenium + requests实现12306全自动买票

    Python + selenium + requests实现12306全自动买票 2020.05.03更新: 下面是新的测试结果: 2021.03.28更新:谷歌浏览器升级导致之前的隐藏方法失效,更新 ...

  9. Mac 模拟登陆12306

    模拟登录12306 结构 1.访问首页,将浏览器窗口最大化 2.找到并点击账号登录,截取全局图片,获得验证码位置坐标,通过该坐标从全局图片里截取验证码图片 3.调用识别平台,返回结果 4.拆分坐标,找 ...

最新文章

  1. 1/10个iPhone Xs = 英伟达最便宜AI计算机,这是唯一的“核弹”?
  2. 用 HAProxy 实现网络流量的负载平衡
  3. Hive常用的SQL命令操作
  4. android webview tel:,Android WebView“tel:”和“mailto:”链接显示未找到网页
  5. 26.智能指针和动态内存
  6. Tomcat虚拟主机搭建Web站点
  7. spark 在启动的时候出现JAVA_HOME not set
  8. tensorflow实现基于LSTM的文本分类方法
  9. Java编程比C编程好吗?《精通Unix下C语言与项目实践》读书笔记(15)
  10. (转)Bootstrap 之 Metronic 模板的学习之路 - (4)源码分析之脚本部分
  11. shell脚本视频学习1
  12. sqoop导出数据时:ERROR tool.ExportTool: Error during export: Export job failed!解决
  13. Ubuntu报错:E: The repository http://ppa.launchpad.net/fcitx-team does not have a Release file.
  14. 使用SHELLEXECUTEINFO 和 ShellExecuteEx
  15. 水经注地图发布服务中件间有什么功能?
  16. matlab的转置和共轭,对Matlab中共轭、转置和共轭装置的区别说明
  17. 如何查看CDRX配置及Log
  18. POI操作Microsoft Office 之 操作PPT简单示例(附源码)
  19. 计算机桌面是快捷方式,我的电脑桌面上的图标都变成快捷方式了怎么处理?
  20. 感恩母亲节主题活动照片作品征集小程序

热门文章

  1. Native App与 Web App 区别
  2. Day171.基本内容 -Dubbo
  3. flask学习之日志logging
  4. nacos名字的由来
  5. 华为AR路由器AR207-S配置pppoe拨号上网图解实例
  6. H3C路由器配置NAT
  7. 推特引流:社交引流的技巧与方法
  8. 使用c#做一个书店买书系统
  9. 人遛狗程序,狗在特定的时间做指定的事情
  10. jconsole连接失败:是否重试?