2019-09-18包,模块

import requests
#引用requests模块
sanguo = requests.get('https://static.pandateacher.com/sanguo.md')
#下载《三国演义》,赋值给sanguo
print(sanguo.content.decode('utf-8'))
booksanguo = open('E:\\booksanguo.txt','w',encoding='utf-8')
booksanguo.write(sanguo.content.decode('utf-8'))
booksanguo.close()

注意:

  • get(……)这里……相当于 URL=……,get(URL),sanguo=requests.get(url)
  • print(sanguo)
    output:

    正确的输出是print(sanguo.content.decode('utf-8')),意思是输出sanguo的content(内容),解码用utf-8

×:print(sanguo)

√:print(sanguo.content.decode('utf-8'))

 

你可能感兴趣的:(2019-09-18包,模块)