文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>python 过滤和抽取 XML 2.5 passed

python 过滤和抽取 XML 2.5 passed

时间:2007-03-05  来源:maojj

#!/usr/bin/env python import xml.etree.ElementTree weblog = xml.etree.ElementTree.parse("C:\Script\modifyCfg\weblog.xml").getroot()   print weblog   aa =  weblog.findall('entry') print aa for entry in weblog.findall("entry"):
    if entry.find('statusCode').text == '200':
        print entry
       
interesting = [entry
               for entry in weblog.findall('entry')
                if entry.find('host').text == '64.172.22.154' and entry.find('statusCode').text == '200']
for  e in interesting:
    print "%s (%s)"% (e.findtext('resource'), e.findtext('byteCount'))
  注:这个例子里有个在[]中循环                      weblog.xml <xml>
<entry>
  <host>64.172.22.154</host>
  <referer>-</referer>
  <userAgent>-</userAgent>
  <dateTime>19/Aug/2001:01:46:01</dateTime>
  <reqID>-0500</reqID>
  <reqType>GET</reqType>
  <resource>/</resource>
  <protocol>HTTP/1.1</protocol>
  <statusCode>200</statusCode>
  <byteCount>2131</byteCount>
</entry>
<entry>
  <host>64.172.22.154</host>
  <referer>-</referer>
  <userAgent>-</userAgent>
  <dateTime>19/Aug/2001:01:46:01</dateTime>
  <reqID>-0500</reqID>
  <reqType>GET</reqType>
  <resource>/</resource>
  <protocol>HTTP/1.1</protocol>
  <statusCode>200</statusCode>
  <byteCount>2131</byteCount>
</entry>
</xml>
  注:xml得有个顶层标签,不然会出错  
相关阅读 更多 +
排行榜 更多 +
找茬脑洞的世界安卓版

找茬脑洞的世界安卓版

休闲益智 下载
滑板英雄跑酷2手游

滑板英雄跑酷2手游

休闲益智 下载
披萨对对看下载

披萨对对看下载

休闲益智 下载