标签:
1 #-*- coding: UTF-8 -*- 2 import sys 3 import lxml 4 import lxml.etree,StringIO 5 6 reload(sys) 7 sys.setdefaultencoding(‘utf-8‘) 8 9 10 def getxml_xpth_content(xpath,filepath,index=0): 11 xml_file=open(filepath,"r") 12 xml_content=xml_file.read() 13 xml_doc=lxml.etree.parse(StringIO.StringIO(xml_content)) 14 alist1=xml_doc.xpath(xpath) 15 elm_content_list=[] 16 for elment in alist1: 17 elm_content=elment.xpath(‘string()‘) 18 elm_content_list.append(elm_content) 19 return elm_content_list 20 detail=getxml_xpth_content("/cn-patent-document/cn-bibliographic-data/cn-publication-reference/document-id/doc-number",r‘C:\Users\j\Desktop\test_desktop_name_must_be_lang_long_lang_ago_lang_long_lang_ago_lang_long_lang_ago_lang_long_lang_ago\1 .XML‘) 21 print detail
标签:
原文地址:http://www.cnblogs.com/oneby/p/5454154.html