标签:load please 城市 pytho python read pre _for htm
# coding=UTF-8
# urllib2_get.py
import urllib2
import StringIO
import gzip
url = 'http://wthrcdn.etouch.cn/weather_mini?city=杭州'
response = urllib2.urlopen(url).read()
data = StringIO.StringIO(response)
gzipper = gzip.GzipFile(fileobj=data)
html = gzipper.read()
print
html
import json
import requests
import sys
if len(sys.argv) < 2:
print('Please city params !')
sys.exit()
# 从命令行获取城市 索引1
city = sys.argv[1]
# 请求天气数据
url = 'http://wthrcdn.etouch.cn/weather_mini?city=' + city
response = requests.get(url)
response.raise_for_status() # 用来检查错误
weatherData = json.loads(response.text) # 返回的是json数据
print(weatherData['data'])
标签:load please 城市 pytho python read pre _for htm
原文地址:https://www.cnblogs.com/jzsg/p/10926193.html