# !/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]