用python提取xml里面的链接源码

Posted 圆柱模板

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用python提取xml里面的链接源码相关的知识,希望对你有一定的参考价值。

  因群里朋友需要提取xml地图里面的链接,就写了这个程序。

  代码:

   

#coding=utf-8
import urllib
import urllib.request 
import re
url=‘http://zhimo.yuanzhumuban.cc/sitemaps.xml‘
html=urllib.request.urlopen(url).read()
html=html.decode(‘utf-8‘)
r=re.compile(r‘(http://zhimo.yuanzhumuban.cc.*?.html)‘)
big=re.findall(r,html)
for i in big:
 print(i)
 op_xml_txt=open(‘xml.txt‘,‘a‘)
 op_xml_txt.write(‘%s
‘%i)

  

   

以上是关于用python提取xml里面的链接源码的主要内容,如果未能解决你的问题,请参考以下文章