即使刮板外壳说DEBUG:爬行(200),也更改了“用户代理”,但仍爬行(404)。

时间:2019-07-12 15:55:44

标签: python scrapy web-crawler

即使在scrapy shell上运行网站的链接时仍收到Crawled(200)消息,运行蜘蛛时我仍收到错误消息404。

我尝试更改用户代理,但仍然收到404消息,并且没有任何内容下载到我的磁盘上。

from scrapy import Spider 
from companies.items import CompaniesItem
import re

class companiesSpider(Spider):
    name = "companies"
    allowed_domains = 'http://startup.miami'
    start_urls = ["http://startup.miami/category/startups/page/" + str(10*i) + "/" for i in range(0, 100)]

    def parse(self, response):
        rows = response.xpath('//div/article').extract()

        for row in rows: 

            link = row.xpath('//h2/a/@href').extract()


            item = Companiestem()
            item['link'] = link

            yield item

这是我经营抓紧的爬行公司(蜘蛛的名字)后得到的东西

(base) C:\Users\Usuario\Desktop\companies>scrapy crawl companies
2019-07-12 11:30:03 [scrapy.utils.log] INFO: Scrapy 1.5.2 started (bot: companies)
2019-07-12 11:30:03 [scrapy.utils.log] INFO: Versions: lxml 4.2.5.0, libxml2 2.9.8, cssselect 1.0.3, parsel 1.5.1, w3lib 1.19.0, Twisted 18.9.0, Python 3.7.1 (default, Dec 10 2018, 22:54:23) [MSC v.1915 64 bit (AMD64)], pyOpenSSL 18.0.0 (OpenSSL 1.1.0j  20 Nov 2018), cryptography 2.4.2, Platform Windows-10-10.0.17763-SP0
2019-07-12 11:30:03 [scrapy.crawler] INFO: Overridden settings: {'BOT_NAME': 'companies', 'DOWNLOAD_DELAY': 2, 'NEWSPIDER_MODULE': 'companies.spiders', 'SPIDER_MODULES': ['companies.spiders']}
2019-07-12 11:30:03 [scrapy.extensions.telnet] INFO: Telnet Password: d853f837a463b0e9
2019-07-12 11:30:03 [scrapy.middleware] INFO: Enabled extensions:
['scrapy.extensions.corestats.CoreStats',
 'scrapy.extensions.telnet.TelnetConsole',
 'scrapy.extensions.logstats.LogStats']
2019-07-12 11:30:04 [scrapy.middleware] INFO: Enabled downloader middlewares:
['scrapy.downloadermiddlewares.httpauth.HttpAuthMiddleware',
 'scrapy.downloadermiddlewares.downloadtimeout.DownloadTimeoutMiddleware',
 'scrapy.downloadermiddlewares.defaultheaders.DefaultHeadersMiddleware',
 'scrapy.downloadermiddlewares.useragent.UserAgentMiddleware',
 'scrapy.downloadermiddlewares.retry.RetryMiddleware',
 'scrapy.downloadermiddlewares.redirect.MetaRefreshMiddleware',
 'scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware',
 'scrapy.downloadermiddlewares.redirect.RedirectMiddleware',
 'scrapy.downloadermiddlewares.cookies.CookiesMiddleware',
 'scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware',
 'scrapy.downloadermiddlewares.stats.DownloaderStats']
2019-07-12 11:30:04 [scrapy.middleware] INFO: Enabled spider middlewares:
['scrapy.spidermiddlewares.httperror.HttpErrorMiddleware',
 'scrapy.spidermiddlewares.offsite.OffsiteMiddleware',
 'scrapy.spidermiddlewares.referer.RefererMiddleware',
 'scrapy.spidermiddlewares.urllength.UrlLengthMiddleware',
 'scrapy.spidermiddlewares.depth.DepthMiddleware']
2019-07-12 11:30:04 [scrapy.middleware] INFO: Enabled item pipelines:
[]
2019-07-12 11:30:04 [scrapy.core.engine] INFO: Spider opened
2019-07-12 11:30:04 [scrapy.extensions.logstats] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2019-07-12 11:30:04 [scrapy.extensions.telnet] DEBUG: Telnet console listening on 127.0.0.1:6024
2019-07-12 11:30:09 [scrapy.core.engine] DEBUG: Crawled (200) <GET http://startup.miami/category/startups/page/0/> (referer: None)
2019-07-12 11:30:09 [scrapy.core.scraper] ERROR: Spider error processing <GET http://startup.miami/category/startups/page/0/> (referer: None)
Traceback (most recent call last):
  File "C:\Users\Usuario\Anaconda3\lib\site-packages\scrapy\utils\defer.py", line 102, in iter_errback
    yield next(it)
  File "C:\Users\Usuario\Anaconda3\lib\site-packages\scrapy\spidermiddlewares\offsite.py", line 30, in process_spider_output
    for x in result:
  File "C:\Users\Usuario\Anaconda3\lib\site-packages\scrapy\spidermiddlewares\referer.py", line 339, in <genexpr>
    return (_set_referer(r) for r in result or ())
  File "C:\Users\Usuario\Anaconda3\lib\site-packages\scrapy\spidermiddlewares\urllength.py", line 37, in <genexpr>
    return (r for r in result or () if _filter(r))
  File "C:\Users\Usuario\Anaconda3\lib\site-packages\scrapy\spidermiddlewares\depth.py", line 58, in <genexpr>
    return (r for r in result or () if _filter(r))
  File "C:\Users\Usuario\Desktop\companies\companies\spiders\companies_spider.py", line 16, in parse
    link = row.xpath('//h2/a/@href').extract()
AttributeError: 'str' object has no attribute 'xpath'
2019-07-12 11:30:11 [scrapy.core.engine] DEBUG: Crawled (200) <GET http://startup.miami/category/startups/page/10/> (referer: None)
2019-07-12 11:30:11 [scrapy.core.scraper] ERROR: Spider error processing <GET http://startup.miami/category/startups/page/10/> (referer: None)
Traceback (most recent call last):
  File "C:\Users\Usuario\Anaconda3\lib\site-packages\scrapy\utils\defer.py", line 102, in iter_errback
    yield next(it)
  File "C:\Users\Usuario\Anaconda3\lib\site-packages\scrapy\spidermiddlewares\offsite.py", line 30, in process_spider_output
    for x in result:
  File "C:\Users\Usuario\Anaconda3\lib\site-packages\scrapy\spidermiddlewares\referer.py", line 339, in <genexpr>
    return (_set_referer(r) for r in result or ())
  File "C:\Users\Usuario\Anaconda3\lib\site-packages\scrapy\spidermiddlewares\urllength.py", line 37, in <genexpr>
    return (r for r in result or () if _filter(r))
  File "C:\Users\Usuario\Anaconda3\lib\site-packages\scrapy\spidermiddlewares\depth.py", line 58, in <genexpr>
    return (r for r in result or () if _filter(r))
  File "C:\Users\Usuario\Desktop\companies\companies\spiders\companies_spider.py", line 16, in parse
    link = row.xpath('//h2/a/@href').extract()
AttributeError: 'str' object has no attribute 'xpath'
2019-07-12 11:30:12 [scrapy.core.engine] DEBUG: Crawled (404) <GET http://startup.miami/category/startups/page/20/> (referer: None)
2019-07-12 11:30:12 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <404 http://startup.miami/category/startups/page/20/>: HTTP status code is not handled or not allowed
2019-07-12 11:30:15 [scrapy.core.engine] DEBUG: Crawled (404) <GET http://startup.miami/category/startups/page/30/> (referer: None)
2019-07-12 11:30:15 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <404 http://startup.miami/category/startups/page/30/>: HTTP status code is not handled or not allowed
2019-07-12 11:30:18 [scrapy.core.engine] DEBUG: Crawled (404) <GET http://startup.miami/category/startups/page/40/> (referer: None)
2019-07-12 11:30:18 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <404 http://startup.miami/category/startups/page/40/>: HTTP status code is not handled or not allowed
2019-07-12 11:30:19 [scrapy.core.engine] DEBUG: Crawled (404) <GET http://startup.miami/category/startups/page/50/> (referer: None)
2019-07-12 11:30:19 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <404 http://startup.miami/category/startups/page/50/>: HTTP status code is not handled or not allowed
2019-07-12 11:30:25 [scrapy.core.engine] DEBUG: Crawled (404) <GET http://startup.miami/category/startups/page/60/> (referer: None)
2019-07-12 11:30:25 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <404 http://startup.miami/category/startups/page/60/>: HTTP status code is not handled or not allowed
2019-07-12 11:30:25 [scrapy.core.engine] DEBUG: Crawled (404) <GET http://startup.miami/category/startups/page/70/> (referer: None)
2019-07-12 11:30:25 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <404 http://startup.miami/category/startups/page/70/>: HTTP status code is not handled or not allowed
2019-07-12 11:30:28 [scrapy.core.engine] DEBUG: Crawled (404) <GET http://startup.miami/category/startups/page/80/> (referer: None)
2019-07-12 11:30:28 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <404 http://startup.miami/category/startups/page/80/>: HTTP status code is not handled or not allowed
2019-07-12 11:30:33 [scrapy.core.engine] DEBUG: Crawled (404) <GET http://startup.miami/category/startups/page/90/> (referer: None)
2019-07-12 11:30:33 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <404 http://startup.miami/category/startups/page/90/>: HTTP status code is not handled or not allowed
2019-07-12 11:30:33 [scrapy.core.engine] INFO: Closing spider (finished)
2019-07-12 11:30:33 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 2379,
 'downloader/request_count': 10,
 'downloader/request_method_count/GET': 10,
 'downloader/response_bytes': 54408,
 'downloader/response_count': 10,
 'downloader/response_status_count/200': 2,
 'downloader/response_status_count/404': 8,
 'finish_reason': 'finished',
 'finish_time': datetime.datetime(2019, 7, 12, 15, 30, 33, 311598),
 'httperror/response_ignored_count': 8,
 'httperror/response_ignored_status_count/404': 8,
 'log_count/DEBUG': 11,
 'log_count/ERROR': 2,
 'log_count/INFO': 16,
 'response_received_count': 10,
 'scheduler/dequeued': 10,
 'scheduler/dequeued/memory': 10,
 'scheduler/enqueued': 10,
 'scheduler/enqueued/memory': 10,
 'spider_exceptions/AttributeError': 2,
 'start_time': datetime.datetime(2019, 7, 12, 15, 30, 4, 199464)}
2019-07-12 11:30:33 [scrapy.core.engine] INFO: Spider closed (finished)

0 个答案:

没有答案