使用 urllib 和 minidom 获取 XML 数据 [英] Using urllib and minidom to fetch XML data
本文介绍了使用 urllib 和 minidom 获取 XML 数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从 XML 服务中获取数据……这个.
I'm trying to fetch data from a XML service... this one.
http://xmlweather.vedur.is/?op_w=xml&type=forec&lang=is&view=xml&ids=1
我正在使用 urrlib 和 minidom,但似乎无法使其正常工作.我已经将 minidom 用于文件而不是 url.
I'm using urrlib and minidom and i can't seem to make it work. I've used minidom with files and not url.
这是我尝试使用的代码
xmlurl = 'http://xmlweather.vedur.is'
xmlpath = xmlurl + '?op_w=xml&type=forec&lang=is&view=xml&ids=' + str(location)
xmldoc = minidom.parse(urllib.urlopen(xmlpath))
有人可以帮我吗?
推荐答案
以下内容应该有效(或者至少让您清楚知道出了什么问题):
The following should work (or at least give you a strong idea about what is going wrong):
from xml.dom.minidom import parse
import urllib
xmlurl = 'http://xmlweather.vedur.is'
xmlpath = xmlurl + '?op_w=xml&type=forec&lang=is&view=xml&ids=' + str(location)
try:
xml = urllib.urlopen(xmlpath)
dom = parse(xml)
except e as Exception:
print(e)
这篇关于使用 urllib 和 minidom 获取 XML 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文