python爬虫之requests的基本使用# 基本的get请求 # response = requests.get('http://httpbin.org/get') # print(respons

import requests
# 基本的get请求
# response = requests.get('http://httpbin.org/get')
# print(response.text)

# 带参数的get请求
# response = requests.get("http://httpbin.org/get?name=germey&age=22")
# print(response.text)
# 或者params的方法
# data={'name':'germey','age':22}
# url='http://httpbin.org/get'
# response = requests.get(url,data)
# print(response.text)

# 获取二进制数据
# response = requests.get("https://github.com/favicon.ico")
# print(type(response.text), type(response.content))
# print(response.text)
# print(response.content)

# 添加headers
# headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36'}
# response = requests.get("https://www.zhihu.com/explore",headers=headers)
# print(response.text)

# post请求
# data = {'name': 'germey', 'age': '22'}
# response = requests.post("http://httpbin.org/post", data=data)
# print(response.text)

# 上传文件
# files = {'file':open('aaa.txt','rb')}
# response = requests.post("http://httpbin.org/post",files=files)
# print(response.text)

# 获取cookie
# response = requests.get("https://www.baidu.com")
# print(response.cookies)
#
# for key,value in response.cookies.items():
#     print(key+"="+value)

类似网址:https://www.cnblogs.com/lei0213/p/6957508.html

你可能感兴趣的:(python)