简体   繁体   中英

parsing xml from url

I want to parse an xml, but I can't find any good tutorials.

    import urllib.request
    import xml.etree.ElementTree as ET

    with urllib.request.urlopen('http://www.nbp.pl/kursy/xml/lastA.xml') as response:
    lasta = response.read()

What exactly is lasta . Is it still xml or a string or something else?

I would suggest BeautifulSoup: Python BeautifulSoup XML Parsing It has a bunch of helper methods that makes navigating a tree-structure (XML, or HTML) easier.

As to your question, 'lasta' is just a string, it hasn't been converted to XML yet. For downloading files over the internet, you may want to consider using the requests package as that is recommended for high-level HTTP operations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM