Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4450162
  • 博文数量: 1214
  • 博客积分: 13195
  • 博客等级: 上将
  • 技术积分: 9105
  • 用 户 组: 普通用户
  • 注册时间: 2007-01-19 14:41
个人简介

C++,python,热爱算法和机器学习

文章分类

全部博文(1214)

文章存档

2021年(13)

2020年(49)

2019年(14)

2018年(27)

2017年(69)

2016年(100)

2015年(106)

2014年(240)

2013年(5)

2012年(193)

2011年(155)

2010年(93)

2009年(62)

2008年(51)

2007年(37)

分类: Python/Ruby

2016-05-24 14:15:59

原文地址:

Intro

在数据抓取的时候经常要使用到HTTP for Humans 的Requests,由于经常做些要代理的 事情,顺便查找下使用Socks5的方法。

Example 1

pip install requesocks

1
2
3
4
5
6
7
8
9
10
11
12
13
if is_open(''): # ;) import requesocks as requests else: import requests session = requests.session() session.proxies = {'http': 'socks5://127.0.0.1:9050', 'https': 'socks5://127.0.0.1:9050'} resp = session.get('', auth=('user', 'pass')) print(resp.status_code) print(resp.headers['content-type']) print(resp.text)  

Python (Python-3.X) library for connection via SOCKS5-proxy

Example 2

pip install PySocks

import socket import socks import requests socks.set_default_proxy(socks.SOCKS5, "127.0.0.1", 9050) socket.socket = socks.socksocket print(requests.get('').text)

你就会得到Tor的代理IP了。

reference

 

阅读(1003) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~