zoukankan      html  css  js  c++  java
  • selenium+ChromeOptions登录抓取北京市社保卡信息

    #coding:utf-8

    from PIL import Image
    from selenium import webdriver
    import random
    import time
    import ydm

    class Login:

    def __init__(self):
    option = webdriver.ChromeOptions()
    option.add_argument('--start-maximized') # 最大化
    option.add_argument('--headless') # 无界面
    self.driver = webdriver.Chrome(chrome_options=option)
    self.url = 'http://www.bjrbj.gov.cn/csibiz/indinfo/login.jsp'

    def t_login(self):
    dr = self.driver
    dr.get(self.url)
    time.sleep(random.uniform(1, 3))
    dr.find_element_by_xpath('//*[@id="i_username"]').send_keys('用户账号')
    dr.find_element_by_xpath('//*[@id="i_password"]').send_keys('用户密码')
    dr.get_screenshot_as_file('q.jpg')
    imgs = dr.find_element_by_xpath('//*[@id="indsafecode"]')
    location = imgs.location # 坐标: {'y': 19, 'x': 498}
    size = imgs.size # 尺寸: {'width': 500, 'height': 22}
    rangle = (
    int(location['x']), int(location['y']), int(location['x'] + size['width']),
    int(location['y'] + size['height']))
    img = Image.open('q.jpg')
    im = img.crop(rangle) # 裁剪图片
    im.save('q_img.png')
    username = '云打码账号'
    password = '密码'
    appid = 4359
    appkey = '0715011dad66b60956de51723d5509c2'
    filename = 'q_img.png'
    codetype = 1004
    timeout = 60
    if (username == 'username'):
    print('请设置好相关参数再测试')
    else:
    yundama = ydm.YDMHttp(username, password, appid, appkey)
    balance = yundama.balance()
    print('balance: %s' % balance)
    cid, result = yundama.decode(filename, codetype, timeout)
    code = result
    print(code)
    dr.find_element_by_xpath('//*[@id="i_safecode"]').send_keys(code)
    dr.find_element_by_xpath('//*[@id="shoujiyanzhengma"]').click()
    time.sleep(random.uniform(2, 3))
    dr.switch_to_alert().accept() #点击alert弹窗
    tel_message = input('请输入短信验证码:')
    time.sleep(random.uniform(3, 5))
    dr.find_element_by_xpath('//*[@id="indform"]/div[4]/input[1]').send_keys(tel_message)
    time.sleep(2)
    dr.find_element_by_xpath('//*[@id="indform"]/div[5]/input').click()
    time.sleep(random.uniform(2, 3))
    print(dr.get_cookies())
    cookie = [item["name"] + "=" + item["value"] for item in dr.get_cookies()]
    cookiestr = ';'.join(item for item in cookie)
    # print(cookiestr)
    with open('cookie.txt', 'w') as f:
    f.write(cookiestr)
    f.close()
    dr.quit()


    l = Login()
    l.t_login()
  • 相关阅读:
    DV型、OV型、EV型证书的主要区别
    HTTPS混合内容解析
    Resin 4.0 部署SSL证书
    中间证书的使用
    IBM LOTUS DOMINO 9 部署SSL证书
    F5部署SSL证书
    百度云部署SSL证书
    阿里云部署SSL证书
    加密,解密web.config数据库连接字符串
    不记得oracle管理员密码,更改oracle sys密码的方法
  • 原文地址:https://www.cnblogs.com/zhangheng1/p/8649719.html
Copyright © 2011-2022 走看看