标签:ica span 模块 dom color ufw 代理 baidu 4.0
官方文档:http://docs.python-requests.org/en/master/
我这里使用的是当前最新的python3.6。
安装
pip3 install requests
1、get请求
import requests url=‘https://www.baidu.com‘ r = requests.get(url) print(r.status_code)
2、post请求
url = ‘https://www.baidu.com‘ data_post = ‘just put your data and use original format‘ r = requests.post(url, data=data_post, verify=True) print(r.status_code)
3、使用代理
import requests url=‘http://docs.python-requests.org/en/master/‘ proxies={ ‘http‘:‘127.0.0.1:8080‘, ‘https‘:‘127.0.0.1:8080‘ } r = requests.get(url,proxies=proxies) print(r.status_code)
4、自定义header和cookie,获取cookie
url = ‘https://weixin.sogou.com/weixin?type=1&s_from=input&query=python&ie=utf8&_sug_=n&_sug_type_=‘ headers = { ‘User-Agent‘: ‘Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1464.0 Safari/537.36‘, ‘Cookie‘: ‘name=JSESSIONID;value=aaaUrhXY8CzPBgs1eXUFw;domain=weixin.sogou.com‘ } r = requests.get(url, headers=headers) # 获取cookie print(r.cookies) print(r.status_code) # print(r.text)
标签:ica span 模块 dom color ufw 代理 baidu 4.0
原文地址:https://www.cnblogs.com/shaosks/p/10189787.html