zoukankan      html  css  js  c++  java
  • python 登录 提交表单数据

    
    # !/usr/bin/env python
    # -*- coding: utf-8 -*-
    import urllib2
    import urllib
    import cookielib
    import json
    import httplib
    import re
    import requests
    import os
    import time
    import requests, requests.utils, pickle
    try:
        import cookielib  # 兼容Python2
    except:
        import http.cookiejar as cookielib
    
    s=requests.session()
    print s.headers
    from requests.packages.urllib3.exceptions import InsecureRequestWarning
    requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
    
    # with open('cook.txt', 'r') as f:
    #    cookies = json.loads(f.read())
    # print cookies
    
    # try:
    #     with open("cookies.txt", "r") as f:
    #         load_cookies = json.loads(f.read())
    #     s.cookies = requests.utils.cookiejar_from_dict(load_cookies)
    #     print s.get('https://fms.lvchengcaifu.com/welcome').content
    # except:
    #
    url = "https://oauth2.lvchengcaifu.com/login"
    headers={
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:54.0) Gecko/20100101 Firefox/54.0',
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
    
    }
    r= s.get(url,headers=headers,verify=False)
    r=r.text
    print r
    print type(r)
    r = r.encode('unicode-escape')
    print type(r)
    p = re.compile('.*_csrf"s+value="(.*?)".*')
    m = p.match(r)
    token = m.group(1)
    print token
    headers={
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:54.0) Gecko/20100101 Firefox/54.0',
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
        'csrf_token': token
    }
    imgurl='https://oauth2.lvchengcaifu.com/Kaptcha.jpg'
    r = s.get(imgurl)
    r = r.content
    # print s
    print type(r)
    print r
    filename = 'E:image.jpg'
    local = open(filename, 'wb')
    local.write(r)
    local.close()
    print "登录二维码已经下载到本地" + "[" + filename + "]"
    
     ##打开图片
    os.system("start %s" % filename);
    code = raw_input('输入验证码: ')
    print code
    print len(code)
    
    ## <input type="hidden" id="_csrf" name="_csrf" value="6f772fd9-14da-40c4-b317-e8d9a4336203" />
    login_url='https://oauth2.lvchengcaifu.com/login/form'
    data = {'username': '1111', 'password': '2222@', '_csrf': token,'validCode':code}
    response = s.post(login_url, data=data,headers=headers)
    print  response.content
    aa=s.cookies
    print '-------------------------------------'
    print aa

  • 相关阅读:
    windows服务创建与管理
    html前端技术:??
    C#整数三种强制类型转换int、Convert.ToInt32()、int.Parse()的区别
    convert转化成特定日期格式
    关于android性能,内存优化(转载)
    不错的Android博客
    十步优化SQL Server中的数据访问(转载)
    数据库SQL优化大总结之 百万级数据库优化方案(转载)
    SQL Server数据库性能优化之SQL语句篇(转载)
    50种方法优化SQL Server数据库查询(转载)
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13348697.html
Copyright © 2011-2022 走看看