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>
  • 相关阅读:
    JS入门(二)
    JavaScript中冒泡排序
    JS入门(一)
    页面的编写(二)
    页面的编写(一)
    编写页面之前的准备
    2019 ICPC徐州网络赛 K.Center
    2019 ICPC徐州网络赛 B.so easy(unordered_map)
    2018-2019 ICPC焦作区域赛B
    2019南昌ICPC网络赛 H.The Nth Item(矩阵快速幂+欧拉降幂+数学处理)
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13348278.html
Copyright © 2011-2022 走看看