python提取xml里面的鏈接源碼詳解
更新時間:2019年10月15日 14:51:03 作者:圓柱模板
在本篇文章里小編給大家整理的是關(guān)于python提取xml里面的鏈接的相關(guān)知識點內(nèi)容,需要的朋友們可以學(xué)習(xí)下。
因群里朋友需要提取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\n'%i)
擴展閱讀:
Python3提取xml文件中的內(nèi)容
import xml.dom.minidom
def find_child(Par_nodes, mystr):
for child_node in Par_nodes:
if(len(child_node.childNodes) > 0):
mystr = find_child(child_node.childNodes, mystr)
elif(child_node.nodeValue != None):
mystr += child_node.data.replace('\n', '')
return mystr
if __name__ == '__main__':
dom1 = xml.dom.minidom.parse('2.XML') #打開xml文件
root = dom1.documentElement #得到文檔元素對象
app_nums = root.getElementsByTagName('base:DocNumber') #按標簽名稱查找,返回標簽結(jié)點數(shù)組
app_num = app_nums[2]
print('專利申請?zhí)枺?+app_num.firstChild.data)
titles = root.getElementsByTagName('business:InventionTitle')
title = titles[0]
print('專利名稱:'+title.firstChild.data)
Paragraphs = root.getElementsByTagName('base:Paragraphs')
abstract = Paragraphs[0]
print('專利摘要:'+abstract.firstChild.data)
company_names = root.getElementsByTagName('base:Name')
company_name = company_names[0]
print('公司名稱:'+company_name.firstChild.data)
mystr = ''
for i in range(len(Paragraphs)):
if (Paragraphs[i].firstChild.data == '發(fā)明內(nèi)容\n\t'):
i+=1
while Paragraphs[i].firstChild.data != '附圖說明\n\t':
mystr = find_child(Paragraphs[i].childNodes, mystr)
i+=1
print('發(fā)明內(nèi)容:' + mystr)
以上就是本次介紹的全部實例代碼知識點,感謝大家的學(xué)習(xí)和對腳本之家的支持。
相關(guān)文章
Python解析命令行讀取參數(shù)--argparse模塊使用方法
這篇文章主要介紹了Python解析命令行讀取參數(shù)--argparse模塊使用方法,需要的朋友可以參考下2018-01-01
機器學(xué)習(xí)實戰(zhàn)之knn算法pandas
這篇文章主要為大家詳細介紹了機器學(xué)習(xí)實戰(zhàn)之knn算法pandas,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-06-06
tensorflow使用range_input_producer多線程讀取數(shù)據(jù)實例
今天小編就為大家分享一篇tensorflow使用range_input_producer多線程讀取數(shù)據(jù)實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-01-01
Python @property及getter setter原理詳解
這篇文章主要介紹了Python @property及getter setter原理詳解,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-03-03
Django csrf 兩種方法設(shè)置form的實例
今天小編就為大家分享一篇Django csrf 兩種方法設(shè)置form的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-02-02
使用python找出list列表中相同元素(指定元素)的所有索引
這篇文章主要給大家介紹了關(guān)于使用python找出list列表中相同元素(指定元素)的所有索引,在平時開發(fā)過程中經(jīng)常遇到需要在數(shù)據(jù)中獲取特定的元素索引的信息,需要的朋友可以參考下2023-08-08

