标签:request 简介 tip name get 进制 text color file
pip install Requests
import requests url = "http://www.mzitu.com" response = requests.get(url) # 获得请求 response.encoding = "utf-8" # 改变其编码 html = response.text # 获得网页内容 binary__content = response.content # 获得二进制数据 raw = requests.get(url, stream=True) # 获得原始响应内容 headers = {‘user-agent‘: ‘my-app/0.0.1‘} # 定制请求头 r = requests.get(url, headers=headers) cookies = {"cookie": "# your cookie"} # cookie的使用 r = requests.get(url, cookies=cookies) # 后续
raw = requests.get(url, stream=True) # 将文本流保存到文件 filename = ‘example.jpg‘ with open(filename, ‘wb‘) as fd: for chunk in raw.iter_content(): fd.write(chunk) fd.close()
标签:request 简介 tip name get 进制 text color file
原文地址:http://www.cnblogs.com/sxhui/p/6127636.html