使用lxml解析xml

#coding:gb2312
import os
import lxml
import lxml.etree,StringIO
import lxml.html as x  

if __name__ == '__main__':
    filelist = os.listdir("/backup/ksearch/query/videos/youku_new/info/")
    for filename in filelist:
        filepath = "/backup/ksearch/query/videos/youku_new/info/" + filename
        f= open(filepath, "r")
        c=f.read()
        doc=lxml.etree.parse(StringIO.StringIO(c)) 
        alist=doc.xpath("/Videos/Video/wid")  
        print len(alist)
        for a in alist:
            print a.text
        

你可能感兴趣的:(C++,c,xml,OS,C#)