如何使用代理与Robobrowser [英] How to use proxy with Robobrowser

查看:140
本文介绍了如何使用代理与Robobrowser的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 http://robobrowser.readthedocs.org/en/latest /readme.html ,(一个基于美丽的汤和请求库的新的python库)在django内。我的django应用包含:

I'm working with http://robobrowser.readthedocs.org/en/latest/readme.html, (a new python library based on the beautiful soup and request libraries) within django. My django app contains :

def index(request):    

    p=str(request.POST.get('p', False)) # p='https://www.yahoo.com/'

    pr="http://10.10.1.10:3128/"
    setProxy(pr)

    browser = RoboBrowser(history=True)
    postedmessage = browser.open(p)
    return HttpResponse(postedmessage)

我想为代码添加一个代理,但是在文档中找不到参考如何做到这一点。是否可以这样做?

I would like to add a proxy to my code but can't find a reference in the docs on how to do this. Is it possible to do this?

编辑:

按照您的建议,我将代码更改为

following your recommendation I've changed the code to

    pr="http://10.10.1.10:3128/"
    setProxy(pr)
    browser = RoboBrowser(history=True)

with:

def setProxy(pr):
    import os
    os.environ['HTTP_PROXY'] = pr
    return

我现在得到:

Django Version: 1.6.4
Exception Type: LocationParseError
Exception Value:    
Failed to parse: Failed to parse: 10.10.1.10:3128

下一步做什么想法?我找不到这个错误的引用

Any ideas on what to do next? I can't find a reference to this error

推荐答案

由于RoboBrowser使用请求库,您可以尝试将代理设置为在请求文档中通过设置环境变量 HTTP_PROXY HTTPS_PROXY

Since RoboBrowser uses the request library, you can try to set the proxies as mentioned in the request docs by setting the environment variables HTTP_PROXY and HTTPS_PROXY.

这篇关于如何使用代理与Robobrowser的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆