zoukankan      html  css  js  c++  java
  • xpath 选择文档所有元素

    //* 选择文档中的所有元素,无论名称如何。
    
    # !/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
    res='<tr><td><a href="browse.jsp?JMSDestination=Consumer.xgmxt.VirtualTopic.HX.CashDetection">Consumer.xgmxt.VirtualTopic.HX.CashDetection</a></td><td>0</td>'
    print type(res)
    s=requests.session()
    user='admin'
    passwd='xx(xx'
    myurl='http://%s:%s@2.2.24.5:8161/admin/queues.jsp' %(user,passwd)
    print myurl
    res1=s.get(myurl)
    res2= res1.content
    print type(res2)
    #<tr><td><a href="browse.jsp?JMSDestination=Consumer.xdxt.VirtualTopic.ECIF.FTPACIMerger">Consumer.xdxt.VirtualTopic.ECIF.FTPACIMerger</a></td><td>0</td><td>41</td><td>0</td><td>0</td><td>
    print dir(etree)
    htmlEmt=etree.HTML(res2)
    print dir(htmlEmt)
    # time.sleep(100)
    result1=htmlEmt.xpath('//*')
    # result2=htmlEmt.xpath('//tr/td/')
    print '----------------------------------------'
    print result1
    i=0
    for x in result1:
         if x.text :
          if re.search("Consumer.",x.text) :
              print result1[i].text
              print result1[i+1].text
              print result1[i + 2].text
              print result1[i + 3].text
         i=i+1
    
    C:Python27python.exe C:/Users/tlcb/PycharmProjects/untitled/httprequest/pt4.py
    
    
    
    Consumer.nbms.VirtualTopic.ECIF.FTPACIMerger
    0
    1
    0
    
    
    
    Consumer.zfdl.VirtualTopic.HX.JieGua
    0
    10
    0
    
    
    
    Consumer.xgmxt.VirtualTopic.HX.CashDetection
    0
    36
    0
    
    
    
    
    
    Consumer.datahub.VirtualTopic.XDXT.ChargeOff
    0
    1
    351252
    
    Process finished with exit code 0
    
    <tr>
    <td><a href="browse.jsp?JMSDestination=Consumer.xgmxt.VirtualTopic.HX.CashDetection">
    
    
    Consumer.xgmxt.VirtualTopic.HX.CashDetection</a></td>
    <td>0</td>
    <td>36</td>
    <td>0</td>
    <td>0</td>
    <td>
  • 相关阅读:
    Linux监控内核SNMP计数器
    wireshark使用手册
    【LinuxShell】echo用法详解
    【Coredump】调试之旅
    汇编指令
    从零开始学Java (五)条件选择
    从零开始学Java (四)输入输出
    Dart基础
    树相关
    递归简介
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13348278.html
Copyright © 2011-2022 走看看