import urllib.request
url = "http://helloworldbook2.com/data/message.txt"
#直接通过url来获取网页数据
print('第一种')
response = urllib.request.urlopen(url)
code = response.getcode()
html = response.read()
mystr = html.decode("utf8")
response.close()
print(mystr)
输出结果如下
第一种
Congratulations! You have just made your computer reach across the internet to get a secret message!
I hope you are enjoying "Hello World! Computer Programming for Kids and Other Beginners".
Have fun!Warren and Carter