#根据a标签,获取href的值

# !/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 = "http://x.x.26.8:8760/"
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:54.0) Gecko/20100101 Firefox/54.0'
}

r = s.get(url, timeout=10, headers=headers)
r=r.text
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://x.x.200.17:7003/loan-web/4ALogon.jsp?tgt=TGT-130672-O1fcAq4HGXFxYjmzfMfuIxAFlqgOfEzNVXja1fDMm5C7IXb7Ox-cas01.example.org" target="_blank">信贷系统</a>
#根据a标签,获取href的值
result=htmlEmt.xpath('//a[@target="_blank"]')
print result
# print type(result)
# print len(result)
for x in result:
    print  x.text
fh1.close()


C:\Python27\python.exe C:/Users/tlcb/PycharmProjects/untitled/httprequest/gj.py
{'Connection': 'keep-alive', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'User-Agent': 'python-requests/2.18.4'}
<type 'str'>
<type 'str'>
<Element html at 0x3008800>
[<Element a at 0x3008a58>, <Element a at 0x3008b20>, <Element a at 0x3008aa8>, <Element a at 0x3008940>, <Element a at 0x3008b70>, <Element a at 0x3008af8>, <Element a at 0x3008e40>, <Element a at 0x3008b48>, <Element a at 0x3008d28>, <Element a at 0x3008c38>, <Element a at 0x3008c10>, <Element a at 0x3008cd8>, <Element a at 0x3008e68>, <Element a at 0x3008d50>, <Element a at 0x3008e18>, <Element a at 0x3008fa8>, <Element a at 0x3008f80>, <Element a at 0x3008df0>, <Element a at 0x3008fd0>, <Element a at 0x3008f30>, <Element a at 0x300be90>, <Element a at 0x300bfd0>, <Element a at 0x300b3f0>, <Element a at 0x300b3c8>, <Element a at 0x300b350>, <Element a at 0x300b238>, <Element a at 0x300b6c0>, <Element a at 0x300b260>, <Element a at 0x300b0a8>, <Element a at 0x300b418>, <Element a at 0x300b4b8>, <Element a at 0x300b760>, <Element a at 0x300b828>, <Element a at 0x300b7d8>]
ebillsapp2:fbsapigateway:7006
ebillsapp1:fbsapigateway:7006
ebillsapp2:fbsbop:7009
ebillsapp1:fbsbop:7009
ebillsapp1:fbsdispatch:7007
ebillsapp2:fbsdispatch:7007
ebillsapp2:fbsinq:7008
ebillsapp1:fbsinq:7008
ebillsapp1:fbsjsh:7002
ebillsapp2:fbsjsh:7002
ebillsapp1:fbsoth:7003
ebillsapp2:fbsoth:7003
ebillsapp1:fbsrcp:7004
ebillsapp2:fbsrcp:7004
ebillsapp1:fbsremit:7005
ebillsapp2:fbsremit:7010
ebillsapp1:fbsremit:7010
ebillsapp2:fbsremit:7005
ebillsapp2:fbsreport:8020
ebillsapp1:fbsreport:8020
mcsapp2:fec:8082
mcsapp1:fec:8082
mcsapp2:fecapigateway:8085
mcsapp1:fecapigateway:8085
mcsapp2:fecdispatch:8086
mcsapp1:fecdispatch:8086
mcsapp1:fecmsggateway:8089
mcsapp2:fecmsggateway:8089
mcsapp2:fecreport:8087
mcsapp1:fecreport:8087
ebillspub2:tms:9999
ebillspub1:tms:9999
ebillspub2:utan-gateway-server:8086
ebillspub1:utan-gateway-server:8086

Process finished with exit code 0



<a href="http://xx.x.26.1:7002/actuator/info" target="_blank">ebillsapp1:fbsjsh:7002</a>


<!doctype html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
  <head>
    <base href="/">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Eureka</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width">

    <link rel="stylesheet" href="eureka/css/wro.css">

  </head>

  <body id="one">
<nav class="navbar navbar-default" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <a class="navbar-brand" href=""><span></span></a>
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav navbar-right">
        <li>
          <a href="">Home</a>
        </li>
        <li>
          <a href="/lastn">Last 1000 since startup</a>
        </li>
      </ul>
    </div>
  </div>
</nav>


    <div class="container-fluid xd-container">
<h1>System Status</h1>
<div class="row">
  <div class="col-md-6">
    <table id='instances' class="table table-condensed table-striped table-hover">
            <tr>
        <td>Environment</td>
        <td>test</td>
      </tr>
      <tr>
        <td>Data center</td>
        <td>default</td>
      </tr>
    </table>
  </div>
  <div class="col-md-6">
    <table id='instances' class="table table-condensed table-striped table-hover">
      <tr>
        <td>Current time</td>
        <td>2019-12-30T08:47:14 +0800</td>
      </tr>
      <tr>
        <td>Uptime</td>
        <td>32 days 21:41</td>
      </tr>
      <tr>
        <td>Lease expiration enabled</td>
        <td>true</td>
      </tr>
      <tr>
        <td>Renews threshold</td>
        <td>0</td>
      </tr>
      <tr>
        <td>Renews (last min)</td>
        <td>368</td>
      </tr>
    </table>
  </div>
</div>

    <h4 id="uptime"><font size="+1" color="red"><b>THE SELF PRESERVATION MODE IS TURNED OFF.THIS MAY NOT PROTECT INSTANCE EXPIRY IN CASE OF NETWORK/OTHER PROBLEMS.</b></font></h4>

<h1>DS Replicas</h1>
<ul class="list-group">
    <li class="list-group-item"><a href="http://x.x.26.8:8761/eureka/">x.x.26.8</a></li>
    <li class="list-group-item"><a href="http://x.x.26.9:8760/eureka/">x.x.26.9</a></li>
</ul>

      <h1>Instances currently registered with Eureka</h1>
      <table id='instances' class="table table-striped table-hover">
        <thead>
          <tr><th>Application</th><th>AMIs</th><th>Availability Zones</th><th>Status</th></tr>
        </thead>
        <tbody>
              <tr>
                <td><b>FBSAPIGATEWAY</b></td>
                <td>
                    <b>n/a</b> (2)
                </td>
                <td>
                    <b></b> (2)
                </td>
                <td>
                    <b>UP</b> (2) -
                        <a href="http://x.x.26.2:7006/actuator/info" target="_blank">ebillsapp2:fbsapigateway:7006</a>
,
                        <a href="http://x.x.26.1:7006/actuator/info" target="_blank">ebillsapp1:fbsapigateway:7006</a>

                </td>
              </tr>
              <tr>
                <td><b>FBSBOP</b></td>
                <td>
                    <b>n/a</b> (2)
                </td>
                <td>
                    <b></b> (2)
                </td>
                <td>
                    <b>UP</b> (2) -
                        <a href="http://x.x.26.2:7009/actuator/info" target="_blank">ebillsapp2:fbsbop:7009</a>
,
                        <a href="http://x.x.26.1:7009/actuator/info" target="_blank">ebillsapp1:fbsbop:7009</a>

                </td>
              </tr>
              <tr>
                <td><b>FBSDISPATCH</b></td>
                <td>
                    <b>n/a</b> (2)
                </td>
                <td>
                    <b></b> (2)
                </td>
                <td>
                    <b>UP</b> (2) -
                        <a href="http://x.x.26.1:7007/actuator/info" target="_blank">ebillsapp1:fbsdispatch:7007</a>
,
                        <a href="http://x.x.26.2:7007/actuator/info" target="_blank">ebillsapp2:fbsdispatch:7007</a>

                </td>
              </tr>
              <tr>
                <td><b>FBSINQ</b></td>
                <td>
                    <b>n/a</b> (2)
                </td>
                <td>
                    <b></b> (2)
                </td>
                <td>
                    <b>UP</b> (2) -
                        <a href="http://x.x.26.2:7008/actuator/info" target="_blank">ebillsapp2:fbsinq:7008</a>
,
                        <a href="http://x.x.26.1:7008/actuator/info" target="_blank">ebillsapp1:fbsinq:7008</a>

                </td>
              </tr>
              <tr>
                <td><b>FBSJSH</b></td>
                <td>
                    <b>n/a</b> (2)
                </td>
                <td>
                    <b></b> (2)
                </td>
                <td>
                    <b>UP</b> (2) -
                        <a href="http://x.x.26.1:7002/actuator/info" target="_blank">ebillsapp1:fbsjsh:7002</a>
,
                        <a href="http://x.x.26.2:7002/actuator/info" target="_blank">ebillsapp2:fbsjsh:7002</a>

                </td>
              </tr>
              <tr>
                <td><b>FBSOTH</b></td>
                <td>
                    <b>n/a</b> (2)
                </td>
                <td>
                    <b></b> (2)
                </td>
                <td>
                    <b>UP</b> (2) -
                        <a href="http://x.x.26.1:7003/actuator/info" target="_blank">ebillsapp1:fbsoth:7003</a>
,
                        <a href="http://x.x.26.2:7003/actuator/info" target="_blank">ebillsapp2:fbsoth:7003</a>

                </td>
              </tr>
              <tr>
                <td><b>FBSRCP</b></td>
                <td>
                    <b>n/a</b> (2)
                </td>
                <td>
                    <b></b> (2)
                </td>
                <td>
                    <b>UP</b> (2) -
                        <a href="http://x.x.26.1:7004/actuator/info" target="_blank">ebillsapp1:fbsrcp:7004</a>
,
                        <a href="http://x.x.26.2:7004/actuator/info" target="_blank">ebillsapp2:fbsrcp:7004</a>

                </td>
              </tr>
              <tr>
                <td><b>FBSREMIT</b></td>
                <td>
                    <b>n/a</b> (4)
                </td>
                <td>
                    <b></b> (4)
                </td>
                <td>
                    <b>UP</b> (4) -
                        <a href="http://x.x.26.1:7005/actuator/info" target="_blank">ebillsapp1:fbsremit:7005</a>
,
                        <a href="http://x.x.26.2:7010/actuator/info" target="_blank">ebillsapp2:fbsremit:7010</a>
,
                        <a href="http://x.x.26.1:7010/actuator/info" target="_blank">ebillsapp1:fbsremit:7010</a>
,
                        <a href="http://x.x.26.2:7005/actuator/info" target="_blank">ebillsapp2:fbsremit:7005</a>

                </td>
              </tr>
              <tr>
                <td><b>FBSREPORT</b></td>
                <td>
                    <b>n/a</b> (2)
                </td>
                <td>
                    <b></b> (2)
                </td>
                <td>
                    <b>UP</b> (2) -
                        <a href="http://x.x.26.2:8020/actuator/info" target="_blank">ebillsapp2:fbsreport:8020</a>
,
                        <a href="http://x.x.26.1:8020/actuator/info" target="_blank">ebillsapp1:fbsreport:8020</a>

                </td>
              </tr>
              <tr>
                <td><b>FEC</b></td>
                <td>
                    <b>n/a</b> (2)
                </td>
                <td>
                    <b></b> (2)
                </td>
                <td>
                    <b>UP</b> (2) -
                        <a href="http://x.x.26.4:8082/actuator/info" target="_blank">mcsapp2:fec:8082</a>
,
                        <a href="http://x.x.26.3:8082/actuator/info" target="_blank">mcsapp1:fec:8082</a>

                </td>
              </tr>
              <tr>
                <td><b>FECAPIGATEWAY</b></td>
                <td>
                    <b>n/a</b> (2)
                </td>
                <td>
                    <b></b> (2)
                </td>
                <td>
                    <b>UP</b> (2) -
                        <a href="http://x.x.26.4:8085/actuator/info" target="_blank">mcsapp2:fecapigateway:8085</a>
,
                        <a href="http://x.x.26.3:8085/actuator/info" target="_blank">mcsapp1:fecapigateway:8085</a>

                </td>
              </tr>
              <tr>
                <td><b>FECDISPATCH</b></td>
                <td>
                    <b>n/a</b> (2)
                </td>
                <td>
                    <b></b> (2)
                </td>
                <td>
                    <b>UP</b> (2) -
                        <a href="http://x.x.26.4:8086/actuator/info" target="_blank">mcsapp2:fecdispatch:8086</a>
,
                        <a href="http://x.x.26.3:8086/actuator/info" target="_blank">mcsapp1:fecdispatch:8086</a>

                </td>
              </tr>
              <tr>
                <td><b>FECMSGGATEWAY</b></td>
                <td>
                    <b>n/a</b> (2)
                </td>
                <td>
                    <b></b> (2)
                </td>
                <td>
                    <b>UP</b> (2) -
                        <a href="http://x.x.26.3:8089/actuator/info" target="_blank">mcsapp1:fecmsggateway:8089</a>
,
                        <a href="http://x.x.26.4:8089/actuator/info" target="_blank">mcsapp2:fecmsggateway:8089</a>

                </td>
              </tr>
              <tr>
                <td><b>FECREPORT</b></td>
                <td>
                    <b>n/a</b> (2)
                </td>
                <td>
                    <b></b> (2)
                </td>
                <td>
                    <b>UP</b> (2) -
                        <a href="http://x.x.26.4:8087/actuator/info" target="_blank">mcsapp2:fecreport:8087</a>
,
                        <a href="http://x.x.26.3:8087/actuator/info" target="_blank">mcsapp1:fecreport:8087</a>

                </td>
              </tr>
              <tr>
                <td><b>TMS</b></td>
                <td>
                    <b>n/a</b> (2)
                </td>
                <td>
                    <b></b> (2)
                </td>
                <td>
                    <b>UP</b> (2) -
                        <a href="http://ebillspub2:9999/actuator/info" target="_blank">ebillspub2:tms:9999</a>
,
                        <a href="http://ebillspub1:9999/actuator/info" target="_blank">ebillspub1:tms:9999</a>

                </td>
              </tr>
              <tr>
                <td><b>UTAN-GATEWAY-SERVER</b></td>
                <td>
                    <b>n/a</b> (2)
                </td>
                <td>
                    <b></b> (2)
                </td>
                <td>
                    <b>UP</b> (2) -
                        <a href="http://x.x.26.9:8086/actuator/info" target="_blank">ebillspub2:utan-gateway-server:8086</a>
,
                        <a href="http://x.x.26.8:8086/actuator/info" target="_blank">ebillspub1:utan-gateway-server:8086</a>

                </td>
              </tr>

        </tbody>
      </table>

      <h1>General Info</h1>

      <table id='generalInfo' class="table table-striped table-hover">
        <thead>
          <tr><th>Name</th><th>Value</th></tr>
        </thead>
        <tbody>
            <tr>
              <td>total-avail-memory</td><td>971mb</td>
            </tr>
            <tr>
              <td>environment</td><td>test</td>
            </tr>
            <tr>
              <td>num-of-cpus</td><td>4</td>
            </tr>
            <tr>
              <td>current-memory-usage</td><td>358mb (36%)</td>
            </tr>
            <tr>
              <td>server-uptime</td><td>32 days 21:41</td>
            </tr>
            <tr>
              <td>registered-replicas</td><td>http://x.x.26.8:8761/eureka/, http://x.x.26.9:8760/eureka/<;/td>
            </tr>
            <tr>
              <td>unavailable-replicas</td><td>http://x.x.26.8:8761/eureka/,http://x.x.26.9:8760/eureka/,&lt;/td>
            </tr>
            <tr>
              <td>available-replicas</td><td></td>
            </tr>
        </tbody>
      </table>

      <h1>Instance Info</h1>

      <table id='instanceInfo' class="table table-striped table-hover">
        <thead>
          <tr><th>Name</th><th>Value</th></tr>
        <thead>
        <tbody>
            <tr>
              <td>ipAddr</td><td>x.x.26.8</td>
            </tr>
            <tr>
              <td>status</td><td>UP</td>
            </tr>
        </tbody>
      </table>
    </div>
    <script type="text/javascript" src="eureka/js/wro.js" ></script>
    <script type="text/javascript">
       $(document).ready(function() {
         $('table.stripeable tr:odd').addClass('odd');
         $('table.stripeable tr:even').addClass('even');
       });
    </script>
  </body>
</html>
发布了3754 篇原创文章 · 获赞 112 · 访问量 346万+

猜你喜欢

转载自blog.csdn.net/zhaoyangjian724/article/details/103761421