Discuss / Python / 练习

练习

Topic source
from urllib import request

def fetch_xml():
    with request.urlopen('http://weather.yahooapis.com/forecastrss?u=c&w=2151330') as f:
        data = f.read()
        d={}
        for k, v in f.getheaders():
            d[k]=v
        d['Data']=data.decode('utf-8')
        return d

print(fetch_xml())

  • 1

Reply