import urllib.parse import urllib.request data = urllib.parse.urlencode({'address': '广东省湛江市霞山区', 'output': 'json','ak':'XX'}) response = urllib.request.urlopen('http://api.map.baidu.com/geocoder/v2/?%s' % data) html = response.read() data = html.decode('utf-8') print(data) f=open('D:\text.cfg','w') f.write(data) f.close()