Requests 是使用 Apache2 Licensed 许可证的 基于Python开发的HTTP 库,其在Python内置模块的基础上进行了高度的封装,符合了Python语言的思想,通俗的说去繁存简。

由于没有看到详细的讲解requests模块怎么写多个请求头和代理ip,这里我做一个实例,引出下文。

示例如下:

import random
import requests header_list = [
#遨游
{"user-agent" : "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)"},
#火狐
{"user-agent" : "Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1"},
#谷歌
{"user-agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11"}
] proxy_list = [
{"http" : "112.115.57.20:3128"}
# {"http" : "root:01@124.88.67.81:80"}
] header = random.choice(header_list)
proxy = random.choice(proxy_list)
try:
req=requests.get('https://www.ipip.net/',headers = header,proxies=proxy,timeout = 2)
print(req.text)
except:
print('no proxies')

给requests模块添加请求头列表和代理ip列表的更多相关文章

  1. Python 使用 requests 模块发送请求的使用及封装

    一.requests 模块基本使用 1.准备接口的URL.请求参数.请求头 # 1. 构造注册.登录.充值请求的url register_url = "注册url" login_u ...

  2. urllib2 post请求方式,带cookie,添加请求头

    #encoding = utf-8 import urllib2import urllib url = 'http://httpbin.org/post'data={"name": ...

  3. springcloud- FeginClient 调用统一拦截添加请求头 RequestInterceptor ,被调用服务获取请求头

    使用场景: 在springcloud中通过Fegin调用远端RestApi的时候,经常需要传递一些参数信息到被调用服务中去,比如从A服务调用B服务的时候, 需要将当前用户信息传递到B调用的服务中去,我 ...

  4. iOS UIWebview添加请求头的两种方式

    1.在UIWebviewDelegate的方法中拦截request,设置request的请求头,废话不多说看代码: - (BOOL)webView:(UIWebView *)webView shoul ...

  5. WKWebView单个界面添加请求头

    https://www.jianshu.com/p/14b9ea4bf1d4 https://github.com/Yeatse/NSURLProtocol-WebKitSupport/blob/ma ...

  6. LoadRunner11脚本小技能之添加请求头+定义变量+响应内容乱码转换打印+事务拆分

    一.添加请求头 存在一些接口,发送请求时需要进行权限验证.登录验证(不加请求头时运行脚本,接口可能会报401等等),所以需要在脚本中给对应请求添加请求头.注意:请求头需在请求前添加,包含url类.su ...

  7. python编写的自动获取代理IP列表的爬虫-chinaboywg-ChinaUnix博客

    python编写的自动获取代理IP列表的爬虫-chinaboywg-ChinaUnix博客 undefined Python多线程抓取代理服务器 | Linux运维笔记 undefined java如 ...

  8. Python-网络爬虫模块-requests模块之请求

    Python原生库urllib库不太方便使用,本着"人生苦短, 我用Python"的珍惜生命精神, 基于urllib, 开发了一个对人类来说, 更好使用的一个库——requests ...

  9. requests模块(post)请求篇

    '''利用parse模块模拟post请求分析百度词典分析步骤:1. 打开F122. 尝试输入单词girl,发现每敲一个字母后都有请求3. 请求地址是 http://fanyi.baidu.com/su ...

随机推荐

  1. C Primer Plus note6

    error: invalid preprocessing directive #difine| 无效的宏定义处理 宏定义define 写成了 difine.

  2. 我的Java编码规范

    1.类名采用驼峰命名法,首字母大写. 2.类变量采用驼峰命名法,首字母小写. 3.方法名是一个动词短语,首字母小写,尽量能描述清楚这个方法的意图. 4.注释在精不在多,一个好的注释要尽量描述出这段代码 ...

  3. 基础架构之Gitlab Runner

    基础架构之Gitlab Runner也是常用的基础设施,我们接着GitLab操作,具体使用GitlabRunner,如果不熟悉可以见官方详细介绍https://docs.gitlab.com/runn ...

  4. asp.net怎么让某一页的 requestEncoding设置成utf-8

    web.config里是这样的 <globalization requestEncoding="gb2312" responseEncoding="gb2312&q ...

  5. android快速启动动画

    http://blog.csdn.net/robert_cysy/article/details/72824513 https://www.cnblogs.com/404map/p/4981099.h ...

  6. M-AddTwoNumbers-未完成

    /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode ...

  7. 杨氏矩阵C++实现

    何为杨氏矩阵?这个网上的介绍很多,下面给出杨氏矩阵搜索算法: #include <iostream> using namespace std; // 杨氏矩阵查找算法 ], int N, ...

  8. Deep Learning Drizzle

    Deep Learning Drizzle Drench yourself in Deep Learning, Reinforcement Learning, Machine Learning, Co ...

  9. SAP S/4HANA CDS View的访问控制实现:DCL介绍

    来自我的同事Xu Miles Authorization Objects are business concept, they are distinguished by business scenar ...

  10. Microsoft Visual C++ 2005 Redistributable 无法卸载问题解决办法

    今日遇到一个问题,Microsoft Visual C++ 2005 Redistributable 无法卸载,弹出的对话框如下所示: 试了一些网上的方法,比如下载vcredist_x86.exe,解 ...