【问题标题】:Scrapy and python: DNS lookup failed: no results for hostname lookup - proxy issue?Scrapy 和 python:DNS 查找失败:主机名查找没有结果 - 代理问题?
【发布时间】:2018-01-24 11:44:02
【问题描述】:

我正在尝试使用 Scrapy 和 Python 从我公司的 IT 和网络中抓取一些页面。我从这里开始使用scrapy 教程https://doc.scrapy.org/en/latest/intro/tutorial.html

当我尝试与教程页面上的代码相同的代码时,我得到了错误:

2018-01-24 11:49:04 [scrapy.downloadermiddlewares.retry] DEBUG: Retrying <GET http://quotes.toscrape.com/robots.txt> (failed 1 times): DNS lookup failed: no results for hostname lookup: quotes.toscrape.com.

因此,我尝试设置我的代理服务器以获取连接,我也必须这样做才能使用 pip install(仅作为示例)。我通过更改教程的代码来做到这一点,使用 Scrapy and proxies 的 Amom 方法:

import scrapy
class QuotesSpider(scrapy.Spider):
    name = "quotes"
    def start_requests(self):
        urls = [
            'http://quotes.toscrape.com/page/1/',
            'http://quotes.toscrape.com/page/2/',
        ]
        for url in urls:
            request = scrapy.Request(url=url, callback=self.parse)
            request.meta['proxy'] = "user@proxy:port"
            yield request

    def parse(self, response):
        page = response.url.split("/")[-2]
        filename = 'quotes-%s.html' % page
        with open(filename, 'wb') as f:
        f.write(response.body)
        self.log('Saved file %s' % filename)

有人知道如何解决这个问题吗?我真的需要让它工作。提前致谢。

【问题讨论】:

  • 你能先在普通浏览器中检查一下代理是否真的在工作吗?
  • 我刚刚尝试使用 Internet Explorer,但是,我不能更改连接设置。
  • 如果可以,请使用 firefox
  • 我也无法使用 Firefox 进行测试,我无法更改连接设置。我试过使用pip --proxy ... install packagename,效果很好。你知道我能做什么吗?
  • 从你的机器上可以打开quotes.toscrape.com/page/1 ??

标签: python web-scraping proxy scrapy


【解决方案1】:

这意味着他们正在阻止scrapy,即他们不允许任何人抓取他们的网站。对不起,你无能为力。

【讨论】:

    猜你喜欢
    • 2021-11-14
    • 2019-11-09
    • 2020-03-08
    • 2014-11-08
    • 1970-01-01
    • 2018-08-02
    • 2021-03-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多