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>
  • 相关阅读:
    【NYOJ】[57]6174问题
    【NYOJ】[56]阶乘因式分解(一)
    【NYOJ】[56]阶乘因式分解(一)
    【看书】for,(do-)while的循环体执行
    【看书】for,(do-)while的循环体执行
    【NYOJ】[41]三个数从小到大排序
    【NYOJ】[41]三个数从小到大排序
    EndNote X7大客户版破解版
    [TomTom]安卓汉化版v1.3,中国及海外地图懒人包
    [TomTom]安卓汉化版v1.3,中国及海外地图懒人包
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13348278.html
Copyright © 2011-2022 走看看