pip install requests-------terminal 窗口安装
import requests 检测安装情况
实例学习--来源于慕课网学习:
import requests
def get_book(sn):
"""获取书本信息9787115428028"""
url ='http://search.dangdang.com/'
rest = requests.get(url,params={
'key': sn,
'act':'input'
})
print(rest.text)
# 打印http状态码200
print(rest.status_code)
# 文件编码
print(rest.encoding)
# 若文件编码不对,可以进行转换
rest.encoding ='utf-8'
# json方式获取数据
#rest.json()
#rest.content()
if __name__ =='__main__':
get_book('9787115428028')