【问题标题】:How to do a wget call via proxy with python?如何使用python通过代理进行wget调用?
【发布时间】:2011-08-08 10:09:30
【问题描述】:

我尝试使用此脚本pdfmeat 从谷歌学者那里获取有关论文的数据。

这个脚本在我的电脑上运行得很好,但是当我尝试把这个脚本放在我的服务器上时,我没有结果。我看到这很可能是我的服务器在谷歌学者的黑名单中,假设我有一个错误(重定向以解决一个章节):

$ wget scholar.google.com
--2011-08-08 04:52:19--  http://scholar.google.com/
Resolving scholar.google.com... 72.14.204.147, 72.14.204.99, 72.14.204.103, ...
Connecting to scholar.google.com|72.14.204.147|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://www.google.com/sorry/?continue=http://scholar.google.com/ [following]
--2011-08-08 04:52:24--  http://www.google.com/sorry/?continue=http://scholar.google.com/
Resolving www.google.com... 74.125.93.147, 74.125.93.99, 74.125.93.103, ...
Connecting to www.google.com|74.125.93.147|:80... connected.
HTTP request sent, awaiting response... 503 Service Unavailable
2011-08-08 04:52:24 ERROR 503: Service Unavailable.

然后我发现wget中有一个选项 --execute "http_proxy=urltoproxy"。我做到了

wget -e "http_proxy=oneHttpProxy" scholar.google.com

我可以从谷歌学者那里保存 index.html。

然后我尝试对 pdfmeat.py 进行相同操作,但我也没有结果。

这是代码:

def getWebdata(self, link, referer='http://scholar.google.com'):
    useragent = 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.8) Gecko/20100214 Ubuntu/9.10 (karmic) Firefox/3.5.8'
    c_web = 'wget --execute "http_proxy=oneHttpProxy" -qO- --user-agent="%s" --load-cookies="%s" "%s" --referer="%s"' % (useragent, WGET_COOKIEFILE, link, referer) 
    c_out = os.popen(c_web)
    c_txt = c_out.read()
    c_out.close()
    if re.search("We're sorry", c_txt) or re.search("please type the characters", c_txt):
        self.logger.critical("scholar captcha")
        if not self.options.quiet:
            print "PDFMEAT: scholar captcha!"
        sys.exit()
    self.logger.debug("getwebdata excerpt: %s" % (re.sub("\n", " ", c_txt[0:255])))
    self.queryLog.append("getwebdata excerpt: %s" % (re.sub("\n", " ", c_txt[0:255])))
    return c_txt

脚本使用模块 os.原始函数没有 wget 的 --execute 选项。

提前致谢

【问题讨论】:

    标签: python wget google-scholar


    【解决方案1】:

    您是否尝试过仅设置 http_proxy 环境。变量?

    所以:

    $ export http_proxy="oneHttpProxy"

    $ python pdfmeat.py ....

    【讨论】:

    • 你能不能用你的原始 wget 命令第一个尝试第一个,所以:$ http_proxy=your_http_proxy wget scholar.google.com
    • 现在的问题是脚本在服务器中非常重要,我不知道该变量的范围
    猜你喜欢
    • 2013-11-22
    • 1970-01-01
    • 2011-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多