• python 获取响应头


    # !/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
    
    s = requests.session()
    print s.headers
    url = "https://licai.yingyinglicai.com/user/login.htm"
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:54.0) Gecko/20100101 Firefox/54.0'
    }
    
    
    login_url = 'http://10.3.200.9/login/VerifyLogin.jsp'
    data = {'formmethod': 'post', 'logfile': '/wui/theme/ecology8/page/login.jsp?templateId=3&logintype=1&gopage=', 'loginid': '444','logintype':'1','submit':'登录','userpassword':'44'}
    # data = urllib.urlencode(data)
    response = s.post(login_url, data=data, headers=headers)
    print  response
    print response.status_code
    print response.content
    url = 'http://10.3.200.9/tailong/syslink/daohanglianjie.jsp'
    r = s.get(url, headers=headers)
    r = r.text
    print r
    print type(r)
    r=r.encode('utf8')
    f=open('fh1.html','w')
    f.write(r)
    f.close()
    
    htmlEmt=etree.HTML(r)
    print htmlEmt
    result=htmlEmt.xpath('//div/a/@href')
    print result
    print type(result)
    arr1=[]
    for x in result:
        print x
        print type(x)
        x1=re.search('http://20.2.200.17:7003/loan-web/4ALogon.jsp',x)
        if  x1:
          arr1.append(x)
    print '-----------------------------'
    print arr1[0]
    print '-----------------------------'
    url = arr1[0]
    r = s.get(url, headers=headers)
    print r.content
    r=r.text
    print  type(r)
    r=r.encode('unicode-escape')
    print type(r)
    print r
    #window.open("/loan-web/go?ComponentURL=/Main.view?TWIN=_top","_top");
    p = re.compile('.*?window.open("(.*?)".*')
    m = p.match(r)
    token = m.group(1)
    print '--------------------------'
    print  token
    print '--------------------------'
    
    url='http://20.2.200.17:7003'+token
    
    print url
    r = s.get(url, headers=headers)
    print r.content
    x=r.headers
    print x
    print type(x)
    for i in x:
        print i+'->'+x[i]
    		
  • 相关阅读:
    C语言程序设计 第二章 数据类型
    C语言程序设计 认识函数
    趣味c语言编程100例(三)
    如何使用 Eset Nod32通行证批量获取精灵
    C语言程序设计 使用库函数参考手册
    C语言程序设计 概述
    C语言程序设计 VC6调试程序(视频)
    趣味c语言编程100例(四)
    java WebService 异常
    数据库战略高度解析(2) 数据库驱动程序
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349000.html
Copyright © 2020-2023  润新知