requests 库

Requests is an HTTP library, written in Python, for human beings.

看文档吧

get

import requests

# Response object called r. We can get all the information we need from this object.
r = requests.get('http://www.jianshu.com/')
print(r)  # Response object
# print(r.text)  # 完整的网页
print(r.status_code)
print(r.encoding)
print(r.headers)
print(r.history)

200
utf-8
{'Transfer-Encoding': 'chunked', 'Date': 'Wed, 10 May 2017 10:22:57 GMT', 'Connection': 'keep-alive', 'Server': 'Tengine', 'X-XSS-Protection': '1; mode=block', 'Cache-Control': 'max-age=0, private, must-revalidate', 'X-Content-Type-Options': 'nosniff', 'Content-Encoding': 'gzip', 'Set-Cookie': '_session_id=d3hYTG9CRUVwSlc5R1pGOUVlYWx3N01hWmZna2tUeitQY1FaeEtqWVlqSiszRWRZQmx4cUtYemJUWCtQTGt1OEw0dGVVL2NVbmFGeEp3OS8rWmgrR2Y3QUdBV2ZUbjQ0RGFoOFNJOGtYQmEyYlEreVRYb0FjZjdkUkdYeGx4cWFJYnhuYVJaTHV4MlUwWGRRMzE1RDQ2UEZvM1FGWnVhYXM2S3E3Y2xJKzE3MThNdzQrdFphNGtQcGNTUXZrTzlRZkZLYSs2M2JjNjkva3VieG5WZXcwOWlvR2NBbG1rcks0NElyWTc3OHpzZDNJZ1d1YnNjL3IySEdpMDdJZE1yWi0tWlZsSDBGSkVRYjNJU0hjQlVlejhZQT09--4d90031280935da9d56f7c8369cbc0efc21c825b; path=/; HttpOnly', 'X-Request-Id': 'f20c3198-2712-4e15-b44a-2affb58d9970', 'X-Via': '1.1 nyidong147:1 (Cdn Cache Server V2.0)', 'X-Runtime': '0.013178', 'Content-Type': 'text/html; charset=utf-8', 'ETag': 'W/"c9d9b2484bda21304db26850fe61b9ce"', 'X-Frame-Options': 'DENY'}
[]

post

你可能感兴趣的:(requests 库)