根據 htmlEmt.xpath('//a[@target="_blank"]') 根據a標籤 查找target=_blank 的值

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

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': '013800','logintype':'1','submit':'登錄','userpassword':'432434343'}
# data = urllib.urlencode(data)
response = s.post(login_url, data=data, headers=headers)
#print  response
print response.status_code
print response.content
print response.headers
time.sleep(1)
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')
print type(r)
f=open('fh1.html','w')
f.write(r)
f.close()

fh1=open('fh1.html','r')
fh2=fh1.read()
#print fh2
print type(fh2)

htmlEmt=etree.HTML(fh2)
print htmlEmt
#<a href="http://20.2.200.17:7003/loan-web/4ALogon.jsp?tgt=TGT-130672-O1fcAq4HGXFxYjmzfMfuIxAFlqgOfEzNVXja1fDMm5C7IXb7Ox-cas01.example.org" target="_blank">信貸系統</a>
#根據div/a標籤,獲取href的值
result=htmlEmt.xpath('//a[@target="_blank"]')
print result
print type(result)
print len(result)
for x in result:
    print x.text


C:\Python27\python.exe "C:\Program Files\JetBrains\PyCharm Community Edition 2017.1.5\helpers\pycharm\_jb_unittest_runner.py" --path C:/Users/tlcb/PycharmProjects/untitled/httprequest/test01.py
Testing started at 19:19 ...
Launching unittests with arguments python -m unittest discover -s C:/Users/tlcb/PycharmProjects/untitled/httprequest -p test01.py -t C:\Users\tlcb\PycharmProjects\untitled\httprequest in C:\Users\tlcb\PycharmProjects\untitled\httprequest
{'Connection': 'keep-alive', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'User-Agent': 'python-requests/2.18.4'}
200














	
 
 



<html>
	<head>
		<script type="text/javascript" src="/js/ecology8/lang/weaver_lang_7_wev8.js"></script>
		<script language="javascript" type="text/javascript" src="/appres/hrm/js/mfcommon_wev8.js"></script>
		<SCRIPT language="javascript" type="text/javascript" src="/wui/common/jquery/jquery.min_wev8.js"></SCRIPT>
		<script type="text/javascript" src="/wui/common/jquery/plugin/jquery.cycle.all_wev8.js"></script>
		<script type="text/javascript" src="/js/jquery/plugins/client/jquery.client_wev8.js"></script>
		<script type="text/javascript" src="/wui/common/jquery/plugin/qrcode/jquery.qrcode_wev8.js"></script>
		<script type="text/javascript" src="/wui/common/jquery/plugin/qrcode/qrcode_wev8.js"></script>
		<script language=javascript src="/wui/theme/ecology8/jquery/js/zDialog_wev8.js"></script>
		<script type="text/javascript" src="/wui/common/jquery/plugin/jquery.overlabel_wev8.js"></script>
		<link href="/css/commom_wev8.css" type="text/css" rel="stylesheet">
	</head>
	<body>
	
	

<script>
document.cookie='logincookiecheck=1541849620056+7B089A5AA3604D86225590F03F786303';
</script>

				<iframe id='idframe' name='idframe' src='' style="display:none">  </iframe>
	      <form action="http://10.3.200.10/ucenter/ucm_user!loginPortal.do" method="post" id="login_form" target="idframe" style="display:none"> 
	        <input type="text" value='013800' id="username" name="username" class="textInput"/><
	        <input type="password" id="loginformpwdalias" value='' name="passwordalias" class="textInput" />
	        <input type="hidden" id="loginformpwd" value='9d8a121ce581499d' name="password" class="textInput" />    
	      </form>
	      <script type="text/javascript">
	      	//document.getElementById('login_form').submit();
	      </script>
		
<script>
try {
	if(document.cookie.indexOf('logincookiecheck=1541849620056+7B089A5AA3604D86225590F03F786303')==-1) {
		document.location.href = '/login/Login.jsp?logintype=1&noAllowIe=yes';
	}
	else {
		document.location.href = '/login/RemindLogin.jsp?RedirectFile=/wui/main.jsp';
	}
}
catch(e){
	document.location.href = '/login/Login.jsp?logintype=1&noAllowIe=yes';
}
</script>

	</body>
</html>

{'Content-Length': '793', 'X-XSS-Protection': '1', 'Content-Encoding': 'gzip', 'Set-Cookie': 'loginfileweaver=%2Flogin%2FLogin.jsp%3Flogintype%3D1%26gopage%3D; path=/; expires=Mon, 12-Nov-2018 11:33:40 GMT, loginidweaver=013800; path=/; expires=Mon, 12-Nov-2018 11:33:40 GMT, loginfileweaver=%2Flogin%2FLogin.jsp%3Flogintype%3D1%26gopage%3D; path=/; expires=Mon, 12-Nov-2018 11:33:40 GMT, loginidweaver=6241; path=/; expires=Mon, 12-Nov-2018 11:33:40 GMT, languageidweaver=7; path=/; expires=Mon, 12-Nov-2018 11:33:40 GMT, JSESSIONID=abcAhk7PZfdU8_xXHz9Bw; path=/, BIGipServerMenhu_new_pool=350094090.20480.0000; path=/', 'Server': 'Resin/3.1.8', 'X-UA-Compatible': 'IE=8', 'Cache-Control': 'private', 'Date': 'Sat, 10 Nov 2018 11:33:40 GMT', 'X-Frame-Options': 'SAMEORIGIN', 'Content-Type': 'text/html; charset=UTF-8'}
<type 'unicode'>
<type 'str'>
<type 'str'>
<Element html at 0x310ac60>
[<Element a at 0x310ad00>, <Element a at 0x310ad50>, <Element a at 0x310a530>, <Element a at 0x310a788>, <Element a at 0x310a800>, <Element a at 0x310a7d8>, <Element a at 0x310a828>, <Element a at 0x310af58>, <Element a at 0x310a760>, <Element a at 0x311b3a0>, <Element a at 0x311b378>, <Element a at 0x311b418>, <Element a at 0x311b350>, <Element a at 0x311b440>, <Element a at 0x311b468>, <Element a at 0x311b3f0>, <Element a at 0x311b490>, <Element a at 0x311b4b8>, <Element a at 0x311b4e0>, <Element a at 0x311b508>, <Element a at 0x311b530>, <Element a at 0x311b558>, <Element a at 0x311b580>, <Element a at 0x311b5a8>, <Element a at 0x311b5d0>, <Element a at 0x311b5f8>, <Element a at 0x311b620>, <Element a at 0x311b648>, <Element a at 0x311b670>, <Element a at 0x311b698>, <Element a at 0x311b6c0>, <Element a at 0x311b6e8>, <Element a at 0x311b710>, <Element a at 0x311b738>, <Element a at 0x311b760>, <Element a at 0x311b788>, <Element a at 0x311b7b0>, <Element a at 0x311b7d8>, <Element a at 0x311b800>, <Element a at 0x311b828>, <Element a at 0x311b850>, <Element a at 0x311b878>, <Element a at 0x311b8a0>, <Element a at 0x311b8c8>, <Element a at 0x311b8f0>, <Element a at 0x311b918>, <Element a at 0x311b940>, <Element a at 0x311b968>, <Element a at 0x311b990>, <Element a at 0x311b9b8>, <Element a at 0x311b9e0>, <Element a at 0x311ba08>, <Element a at 0x311ba30>, <Element a at 0x311ba58>, <Element a at 0x311ba80>, <Element a at 0x311baa8>, <Element a at 0x311bad0>, <Element a at 0x311baf8>, <Element a at 0x311bb20>, <Element a at 0x311bb48>, <Element a at 0x311bb70>, <Element a at 0x311bb98>, <Element a at 0x311bbc0>, <Element a at 0x311bbe8>, <Element a at 0x311bc10>, <Element a at 0x311bc38>, <Element a at 0x311bc60>, <Element a at 0x311bc88>, <Element a at 0x311bcb0>, <Element a at 0x311bcd8>, <Element a at 0x311bd00>, <Element a at 0x311bd28>, <Element a at 0x311bd50>, <Element a at 0x311bd78>, <Element a at 0x311bda0>, <Element a at 0x311bdc8>, <Element a at 0x311bdf0>, <Element a at 0x311be18>, <Element a at 0x311be40>]
<type 'list'>
79
信貸系統
信貸系統(授權碼)
外部數據管理平臺
非現場監測系統
風險事件報送系統
國際結算系統
綜合積分系統
清單傳遞
隨貸通卡管理系統
信用卡系統(老)
信用卡管理系統(新)
移動辦公靜態密碼修改
移動辦公用戶管理系統
IT服務管理平臺(自助登記)
個人存款查詢(新)
數據中心綜合信息平臺
TeamBition
IT項目管理平臺
運維管理平臺
手機管理系統
移動應用管理平臺
統一認證管理
綜合理財管理後臺
信託資管低櫃系統
信託資管管理後臺
綜合理財低櫃系統
惠衆徵信系統
小微金融地圖
CRM系統
電子銀行管理系統
動態密碼鎖管理系統(新)
金融移動服務站業務管理系統
自助機具管理系統
小魚Bank後管系統
移動應用管理平臺
移動設備管理平臺
工單協作平臺
企業網上銀行演示
企業網上銀行
個人網上銀行演示
個人網上銀行
資產證券化系統
同業資金業務系統
安防設備管理系統
安全身份認證
安保在線考試系統
總賬系統
資金轉移定價系統
FTP資金轉移定價系統
新財務覈算系統
增值稅管理系統
企業郵箱
BPM系統
知識中心(老)
辦公用品
訂餐管理
網上訂餐
舊版辦公平臺
舊版首頁
新人力資源系統
轉正考試系統
新績效考覈系統
行政考覈系統
員工投訴專線
回單系統
票據管理系統
超級網銀管理平臺
反假貨幣信息系統
網上憑證查詢系統
櫃面移動服務管理系統
節節高計算器
隆情計算器
753檢查
叫號機管理系統
事後監督管理系統
反洗錢系統
新一代反洗錢工作平臺
合規和操作風險管理系統
黑名單監控管理系統


Ran 0 tests in 0.000s

OK

Process finished with exit code 0
Empty test suite.

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章