---
title: "Python的urllib2的代理设置"
author: "riching"
date: "2013-11-01T17:58:51Z"
tags: []
categories: ["编程语言"]
slug: "python-urllib2"
draft: false
lastmod: "2013-11-01T17:58:51Z"
id: 1968742
url: "https://riching.iteye.com/blog/1968742"
---

程序中使用代理的应用场景主要是：爬去有访问频率限制的网站的数据或者用于刷票等
代理的代码很简单，可以和上一篇的cookie、header等一起设置，具体可参考官方api

```java

 proxy_info = "219.232.47.153:80"
 proxy_handler = urllib2.ProxyHandler({"http" : "http://%s/" % proxy_info})
 proxy_opener = urllib2.build_opener(proxy_handler)

 之后
 urllib2.install_opener(proxy_opener)
 或者
 proxy_opener.open(url).read()

```