其他分享
首页 > 其他分享> > requests

requests

作者:互联网

 

import requests

# response=requests.get('http://www.baidu.com')
# print(response.status_code)
# response.encoding='utf-8' # 指定编码格式
# # print(response.text)  #返回文本类型格式
# # print(response.cookies)# 返回cookies
# # print(response.encoding) # 返回编码格式
# # print(response.url)
# print(response.content)  # 返回是byte类型的数据
# print(response.headers) # 返回响应头
# # print(response.json())  # 获取json类型的数据

爬取图片

#response=requests.get('https://img2.baidu.com/it/u=3635204433,939208923&fm=253&fmt=auto&app=138&f=JPEG?w=375&h=500')
# print(response.content)
# with open('图片.png','wb')as f:
#     f.write(response.content)

爬取视频   一定要找到真实的地址

# response=requests.get('https://live-s3m.mediav.com/nativevideo/27145dc845505ca4127e2f8f711cf789-bit_cloud512.mp4')
# with open('视频.mp4','wb')as f:
#     for i in response.iter_content(chunk_size=1024):
#         f.write(i)
response=requests.get('https://vd2.bdstatic.com/mda-km109ah23gvgw4ba/sc/mda-km109ah23gvgw4ba.mp4?v_from_s=hkapp-haokan-nanjing&auth_key=1657265724-0-0-a1e98f013529a6a80d61b57ce26e51b8&bcevod_channel=searchbox_feed&pd=1&cd=0&pt=3&logid=0324767344&vid=7395144846376198296&abtest=103334_1&klogid=0324767344')
with open('儿童视频.mp4','wb')as f:
    for i in response.iter_content(chunk_size=1024):
        f.write(i)

 

标签:get,content,mp4,print,requests,response
来源: https://www.cnblogs.com/gm11/p/16461331.html