互联网访问
urllib
urllib是用于打开URL的Python模块。
import urllib.request
# open a connection to a URL using urllib
webUrl = urllib.request.urlopen(‘https://china-testing.github.io/address.html‘)
get the result code and print it
print (“result code: “ + str(webUrl.getcode()))
read the data from the URL and print it
data = webUrl.read()
print (data)

json
json是一种受JavaScript对象文字语法启发的轻量级数据交换格式。是目前互联网最流行的数据交换格式。
json公开了标准库marshal和pickle模块的用户所熟悉的API。
>>> import json
>>> json.dumps([‘foo’, {‘bar’: (‘baz’, None, 1.0, 2)}])
‘[“foo”, {“bar”: [“baz”, null, 1.0, 2]}]’
>>> print(json.dumps(“\”foo\bar”))
“\”foo\bar”
>>> print(json.dumps(‘\u1234’))
“\u1234”
>>> print(json.dumps(‘\‘))
“\“
>>> print(json.dumps({“c”: 0, “b”: 0, “a”: 0}, sort_keys=True))
{“a”: 0, “b”: 0, “c”: 0}
>>> from io import StringIO
>>> io = StringIO()
>>> json.dump([‘streaming API’], io)
>>> io.getvalue()
‘[“streaming API”]’
