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
?