python requests使用socks5的例子

网络爬虫由于一个ip频繁访问同一网站,容易返回456或者被长时间封禁。

特别的本机有socks5客户端的设置如下,前提是已经安装了socks5的客户端软件,并且启动起来在固定端口为本机提供服务。

使用前先更新requests版本为支持socks的版本。

pip install -U requests[socks]
import requests

my_proxies={"http":"http://127.0.0.1:1080","https":"https://127.0.0.1:1080"}
resp=requests.get("http://www.some.com",proxies=my_proxies,timeout=5)
print(resp.text)

注意其中的地址协议写的是http和https。

以上这篇python requests使用socks5的例子就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我们。

(0)

相关推荐

  • 解决Python requests库编码 socks5代理的问题

    编码问题 response = requests.get(URL, params=params, headers=headers, timeout=10) print 'self.encoding',response.encoding output: self.encoding ISO-8859-1 查了一些相关的资料,看了下requests的源码,只有在服务器响应的头部包含有Content-Type,且里面有charset信息,requests能够正确识别,否则就会使用默认的 ISO-8859

  • Python写的Socks5协议代理服务器

    直接上代码: #!/usr/bin/python # Filename s5.py # Python Dynamic Socks5 Proxy # Usage: python s5.py 1080 # Background Run: nohup python s5.py 1080 & import socket, sys, select, SocketServer, struct, time class ThreadingTCPServer(SocketServer.ThreadingMixIn

  • python requests使用socks5的例子

    网络爬虫由于一个ip频繁访问同一网站,容易返回456或者被长时间封禁. 特别的本机有socks5客户端的设置如下,前提是已经安装了socks5的客户端软件,并且启动起来在固定端口为本机提供服务. 使用前先更新requests版本为支持socks的版本. pip install -U requests[socks] import requests my_proxies={"http":"http://127.0.0.1:1080","https":

  • python requests指定出口ip的例子

    爬虫需要,一个机器多个口,一个口多个ip,为轮询这些ip demo #coding=utf-8 import requests,sys,socket from requests_toolbelt.adapters import source reload(sys) sys.setdefaultencoding('utf-8') s = requests.Session() new_source = source.SourceAddressAdapter('192.168.4.2') s.moun

  • python requests库的使用

    requests模块 使用requests可以模拟浏览器的请求,requests模块的本质是封装了urllib3模块的功能,比起之前用到的urllib,requests模块的api更加便捷 requests库发送请求将网页内容下载下来以后,并不会执行js代码,这需要我们自己分析目标站点然后发起新的request请求,但是selenium模块就可以执行js的操作. 安装: pip3 install requests 请求方式:主要用到的就get和post两种 #各种请求方式:常用的就是reques

  • Python Requests安装与简单运用

    requests是python的一个HTTP客户端库,跟urllib,urllib2类似,那为什么要用requests而不用urllib2呢?官方文档中是这样说明的: python的标准库urllib2提供了大部分需要的HTTP功能,但是API太逆天了,一个简单的功能就需要一大堆代码. 我也看了下requests的文档,确实很简单,适合我这种懒人.下面就是一些简单指南. 插播个好消息!刚看到requests有了中文翻译版,建议英文不好的看看,内容也比我的博客好多了,具体链接是:http://cn

  • 基于python requests库中的代理实例讲解

    直接上代码: #request代理(proxy) """ 1.启动代理服务器Heroku,相当于aliyun 2.在主机1080端口启动Socks 服务 3.将请求转发到1080端口 4.获取相应资源 首先要安装包pip install 'requests[socksv5]' """ import requests #定义一个代理服务器,所有的http及https都走socks5的协议,sock5相当于http协议,它是在会话层 #把它转到本机的

  • Python requests库用法实例详解

    本文实例讲述了Python requests库用法.分享给大家供大家参考,具体如下: requests是Python中一个第三方库,基于 urllib,采用 Apache2 Licensed 开源协议的 HTTP 库.它比 urllib 更加方便,可以节约我们大量的工作,完全满足 HTTP 测试需求.接下来将记录一下requests的使用: 安装 要使用requests库必须先要安装: pip install requests 创建请求 通过requests库发出一个请求非常简单,首先我们先导入

  • Python Requests库基本用法示例

    本文实例讲述了Python Requests库基本用法.分享给大家供大家参考,具体如下: requests是python的一个http client库,提供了一套简捷的API供开发者使用.下面简单介绍一下其安装和使用.这里是官方文档. 0 安装 pip install requests 1 发送请求 r=requests.get('https://www.baidu.com') print r.status_code,r.text r=requests.post('http://httpbin.

  • Python + Requests + Unittest接口自动化测试实例分析

    本文实例讲述了Python + Requests + Unittest接口自动化测试.分享给大家供大家参考,具体如下: 1. 介绍下python的requests模块 Python Requests快速入门 :http://cn.python-requests.org/zh_CN/latest/ 想必会Python基础的小伙伴们一看就懂了 2. Requests接口自动化测试: 2.1 如何利用这么利器进行接口测试,请看小demo: # -*- coding:utf-8 -* import re

  • Python中使用socks5设置全局代理的方法示例

    0x01介绍 PySocks使您可以通过SOCKS和HTTP代理服务器发送流量.它是SocksiPy的现代分支,具有错误修复和其他功能. 0x02 安装 λ pip3 install Pysocks 0x03 测试 正常请求,httperror无法获得 加入socks5代理后,可以获得当前程序的全局代理可以 正常访问 import socket import socks socks.set_default_proxy(socks.SOCKS5, "127.0.0.1", 10808)

随机推荐