python提取xml里面的鏈接源碼詳解
更新時(shí)間:2019年10月15日 14:51:03 作者:圓柱模板
在本篇文章里小編給大家整理的是關(guān)于python提取xml里面的鏈接的相關(guān)知識(shí)點(diǎn)內(nèi)容,需要的朋友們可以學(xué)習(xí)下。
因群里朋友需要提取xml地圖里面的鏈接,就寫了這個(gè)程序。
代碼:
#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)
擴(kuò)展閱讀:
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 #得到文檔元素對(duì)象
app_nums = root.getElementsByTagName('base:DocNumber') #按標(biāo)簽名稱查找,返回標(biāo)簽結(jié)點(diǎn)數(shù)組
app_num = app_nums[2]
print('專利申請(qǐng)?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 != '附圖說(shuō)明\n\t':
mystr = find_child(Paragraphs[i].childNodes, mystr)
i+=1
print('發(fā)明內(nèi)容:' + mystr)
以上就是本次介紹的全部實(shí)例代碼知識(shí)點(diǎn),感謝大家的學(xué)習(xí)和對(duì)腳本之家的支持。
相關(guān)文章
numpy中幾種隨機(jī)數(shù)生成函數(shù)的用法
numpy是Python中常用的科學(xué)計(jì)算庫(kù),其中也包含了一些隨機(jī)數(shù)生成函數(shù),本文主要介紹了numpy中幾種隨機(jī)數(shù)生成函數(shù)的用法,具有一定的參考價(jià)值,感興趣的可以了解一下2023-11-11
django數(shù)據(jù)模型(Model)的字段類型解析
這篇文章主要介紹了django數(shù)據(jù)模型(Model)的字段類型,文中給大家提到了django數(shù)據(jù)模型on_delete, db_constraint的使用,需要的朋友可以參考下2019-12-12
Python PyWebIO提升團(tuán)隊(duì)效率使用介紹
這篇文章主要為大家介紹了Python PyWebIO提升團(tuán)隊(duì)效率使用介紹,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-01-01
Python使用Socket(Https)Post登錄百度的實(shí)現(xiàn)代碼
以前都是用一些高級(jí)模塊,封裝的比較好,今天嘗試使用socket模塊登錄百度,弄了半天才弄好,主要由于百度在登陸頁(yè)使用了https,我們需要對(duì)socket進(jìn)行一定處理2012-05-05
C++和python實(shí)現(xiàn)阿姆斯特朗數(shù)字查找實(shí)例代碼
這篇文章主要給大家介紹了關(guān)于C++和python實(shí)現(xiàn)阿姆斯特朗數(shù)字查找的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12

