用到的包
lmxl
代码
from lxml import etree import re html = etree.parse('sitemap.xml') rs = html.xpath('.') index = 0 count = 0 full_text = b"" for elem in rs[0]: count += 1 full_text += etree.tostring(elem) if count >= 9999: count = 0 index += 1 filename = format(str(index) + ".xml") with open(filename, 'wb') as f: f.write(full_text) full_text = b"" with open(format(str(index+1)+".xml"), 'wb') as f: f.write(full_text)