怎么设置代理,详情见邮件

607 views
Skip to first unread message

chen

unread,
May 22, 2015, 2:53:13 AM5/22/15
to Roy Binux, pyspide...@googlegroups.com

您好,Binux

 

我们公司在访问外网的时候需要加代理,如下图:

 

pyspider里怎么设置代理呢? 是像我下面这样设置吗?

image001.png
image002.png

自由

unread,
May 22, 2015, 3:04:04 AM5/22/15
to chen, Roy Binux, pyspider-users
http://docs.pyspider.org/en/latest/Command-Line/
最简单的办法就是添加配置文件,配置文件里写代理配置。如
{
  "fetcher": {
    "proxy": daili.com:8080
  }
}
然后启动pyspider的时候就可以用-c 配置文件名 这样的启动

当然也可以直接在项目里添加只针对这个项目的代理,就像你写的这样

    crawl_config = {
        "fetcher": {           
            "
proxy": daili.com:8080 ,
        }
    }
好像是这样,不过我没用过代理

有不对的地请指正


------------------ 原始邮件 ------------------
发件人: "chen";<czw...@163.com>;
发送时间: 2015年5月22日(星期五) 下午2:49
收件人: "'Roy Binux'"<r...@binux.me>; "pyspider-users"<pyspide...@googlegroups.com>;
主题: [pyspider-users] 怎么设置代理,详情见邮件
--
You received this message because you are subscribed to the Google Groups "pyspider-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyspider-user...@googlegroups.com.
To post to this group, send email to pyspide...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyspider-users/054301d0945b%2470b50270%24521f0750%24%40163.com.
For more options, visit https://groups.google.com/d/optout.
3ECDF5C6@DA495C09.DCD45E55
A890E449@DA495C09.DCD45E55

chen

unread,
May 22, 2015, 3:21:32 AM5/22/15
to 自由, Roy Binux, pyspider-users

自由:

您好!

 

class Handler(BaseHandler):

    crawl_config = {

        "fetcher": {           

            "proxy": "proxy.asiainfo.com:8080" ,

        }

 

}

…… ……

 

我在程序中这样写不行哈,报错了,报错信息如下:

[E 150522 15:07:15 base_handler:192] crawl() got unexpected keyword argument: ['fetcher']

    Traceback (most recent call last):

      File "/usr/local/lib/python2.7/site-packages/pyspider/libs/base_handler.py", line 185, in run_task

        result = self._run_task(task, response)

      File "/usr/local/lib/python2.7/site-packages/pyspider/libs/base_handler.py", line 169, in _run_task

        return self._run_func(function, response, task)

      File "/usr/local/lib/python2.7/site-packages/pyspider/libs/base_handler.py", line 148, in _run_func

        return function(*arguments[:len(args) - 1])

      File "<douban_list>", line 24, in index_page

      File "/usr/local/lib/python2.7/site-packages/pyspider/libs/base_handler.py", line 341, in crawl

        return self._crawl(url, **kwargs)

      File "/usr/local/lib/python2.7/site-packages/pyspider/libs/base_handler.py", line 286, in _crawl

        raise TypeError('crawl() got unexpected keyword argument: %s' % kwargs.keys())

    TypeError: crawl() got unexpected keyword argument: ['fetcher']

 

没有 fetcher 这个key

 

另外:我把  "proxy.asiainfo.com:8080" 这个双引号去掉,报语句错误,应该是key value 都需要用双引号 括起来。

发件人: 自由 [mailto:douqia...@qq.com]
发送时间: 2015522 15:04
收件人: chen; 'Roy Binux'; pyspider-users
主题: 回复:[pyspider-users] 怎么设置代理,详情见邮件

image001.png
image002.png

自由

unread,
May 22, 2015, 3:24:05 AM5/22/15
to chen, &#39;Roy Binux&#39;, pyspider-users
好吧,我也没这么用过,我看命令行有这个参数感觉应该可以这样用。这样不行你就写配置文件吧,这个应该是可以的。我用配置文件指定过数据库,webui的参数,都能生效


------------------ 原始邮件 ------------------
发件人: "chen";<czw...@163.com>;
发送时间: 2015年5月22日(星期五) 下午3:17
收件人: "自由"<douqia...@qq.com>; "'Roy Binux'"<r...@binux.me>; "'pyspider-users'"<pyspide...@googlegroups.com>;
主题: 答复: 回复:[pyspider-users] 怎么设置代理,详情见邮件
17CEB4DA@D6BCD250.8CD95E55
B19D1706@D6BCD250.8CD95E55

Roy Binux

unread,
May 22, 2015, 3:28:40 AM5/22/15
to 自由, chen, pyspider-users
{
  "fetcher": {
    "proxy": "daili.com:8080"
  }
}

是 config.json 的写法

在脚本中,应该用 `self.crawl` http://docs.pyspider.org/en/latest/apis/self.crawl/ 的参数:

self.crawl(url, callback=self.callback, proxy="proxy.example.com:8080")

或者

class Handler(BaseHandler):
    crawl_config = {
            "proxy": "proxy.asiainfo.com:8080" ,
        }


17CEB4DA@D6BCD250.8CD95E55
B19D1706@D6BCD250.8CD95E55
17CEB4DA@D6BCD250.8CD95E55
B19D1706@D6BCD250.8CD95E55

自由

unread,
May 22, 2015, 3:29:52 AM5/22/15
to &#39;Roy Binux&#39;, chen, pyspider-users
原来是这样啊,看来参数不需要组件名,我以为也是json呢。


------------------ 原始邮件 ------------------
发件人: "&#39;Roy Binux&#39;";<r...@binux.me>;
发送时间: 2015年5月22日(星期五) 下午3:28
收件人: "自由"<douqia...@qq.com>; "chen"<czw...@163.com>; "pyspider-users"<pyspide...@googlegroups.com>;
主题: Re: 答复: 回复:[pyspider-users] 怎么设置代理,详情见邮件
C37BF070@0940AB35.EBDA5E55
2D7CA27B@0940AB35.EBDA5E55
Reply all
Reply to author
Forward
0 new messages