zoukankan      html  css  js  c++  java
  • python windows编码乱码问题

    # !/usr/bin/env python
    # -*- coding: utf-8 -*-
    import urllib2
    import urllib
    import cookielib
    import json
    import httplib
    import re
    import requests
    from lxml import etree
    import StringIO
    import time
    import datetime
    import hashlib
    import sys
    reload(sys)
    import io
    # sys.stdout=io.TextIOWrapper(sys.stdout.buffer,encoding='gb18030')
    s = requests.session()
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:54.0) Gecko/20100101 Firefox/54.0'
    }
    data = {
        'formmethod': 'post',
        'logfile': '/wui/theme/ecology8/page/login.jsp?templateId=3&logintype=1&gopage=',
        'loginid':'013800',
        'logintype':'1',
        'isie':'false',
        'submit':u'登录',
        'userpassword':'Xxxx6'
    }
    print data
    login_url = 'http://20.3.200.19/login/VerifyLogin.jsp'
    try :
    response = s.post(login_url, data=data, headers=headers,timeout=10)
    print response.content
    print response.status_code
    res= s.get('http://20.3.200.19/tailong/syslink/daohanglianjie.jsp').content
    print res
    except:
        print 'login failed'
    htmlEmt=etree.HTML(res)
    result=htmlEmt.xpath('//div/a/@href')
    print result
    print type(result)
    for x in result:
        if re.search('dcdp-admin',x):
            dcdpurl= x
    print dcdpurl
    p=re.compile('.*tgt=(.*)')
    m=p.match(dcdpurl)
    tgt= m.group(1)
    print tgt
    data={'bsOrgId':'999999998',
          'dataOrgId':'999999998',
          'dataOrgNm':'浙江泰隆商业银行股份有限公司',
          'extentionRoles':'035136f3-cacf-4310-bdc9-04fc33ca3fef,GROUP01,0b4dc08c-689c-43f5-aa5b-04c455226b56,GROUP22',
          'orgId':'992200401',
          'orgNm':'信息开发部应用运营中心应用支持科',
          'portalCode':'013800',
           'resId':'bdd5168a',
          'roleId':'DEPT18_SUPPORT',
          'roleDesc':'总行-信息开发部_应用支持',
          'roleNm':'总行-信息开发部_应用支持',
          'rolecode':'P1110',
          'rolename':'职能序列员工-技术一类员工-总行技术一类员工',
          'ticket':tgt,
          'userNm':'xx',
          'orgNm':'信息开发部应用运营中心运营开发科',
          'userId':'015208'}
    print s.post('http://10.3.200.49:7002/dbportal-dsb/ssoLogin.do',data=data).content
    print s.get('http://10.3.200.49:7002/dbportal-dsb/index.do').content
    #res1=s.get('http://10.3.253.15:7012/WebReport/ReportServer?_=1594870935632&__boxModel__=true&op=page_content&;sessionID=35739&pn=1&__webpage__=true&_paperWidth=1340&_paperHeight=175&__fit__=false')
    res1= s.get('http://10.3.253.15:7012/WebReport/ReportServer?_=1594864802746&__boxModel__=true&op=page_content&;sessionID=61077&pn=1&__webpage__=true&_paperWidth=1340&_paperHeight=196&__fit__=false').content
    print type(res1)
    print res1
    res1=res1.decode('gbk')
    print type(res1)
    htmlEmt=etree.HTML(res1)
    
    result=htmlEmt.xpath('//div[@heavytd="light"]')
    if result :
        print '1111111'
    else:
        print '222222222'
    
    for x in result:
        print x.text
    
    
    
    <type 'str'>
    <type 'unicode'>
    
  • 相关阅读:
    C+= concurrent_queue 线程安全测试
    c++ 枚举 在函数中的应用
    shell脚本积累
    hibernate+spring整合增删改事务错误
    checkbox批量删除功能
    html全选和取消全选JS
    hibernate+pageBean实现分页dao层功能代码
    table样式
    WebStorm 11 Lisence server
    Kb,KB,Kbps,Mb,Mbps等一些列概念
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13348280.html
Copyright © 2011-2022 走看看