Scrapy爬行0页,响应状态为200

时间:2016-08-17 09:33:18

标签: python scrapy web-crawler

我正在测试Scrapy来抓取网页。我无法抓取我想要的页面,我找不到原因。谁能解决我的问题?

P.S。对于某人的提醒,上一个网页显示错误。我改变了路径。

total_corner_spider.py

name = "totalcorner"
allowed_domains = ["totalcorner.com"]
start_urls = [
    "http://www.totalcorner.com/match/corner_stats/57868009",
]

def parse(self, response):
    histories = Selector(response).xpath('//*[@id="home_history_table"]/tbody')
    for history in histories:
        item = HistoryItem()
        item['leagueId'] = history.xpath(
            'a[@data-league_id').extract()[0]
        yield item

items.py

from scrapy.item import Item, Field


class HistoryItem(Item):
    leagueId = Field()

之后

>>> scrapy crawl totalcorner -o some.json,

我发现.json文件只包含“[”

之后

>>> scrapy crawl totalcorner

我从终端获得以下日志:

2016-08-17 17:20:50 [scrapy] INFO: Scrapy 1.1.1 started (bot: totalcorner)
    2016-08-17 17:20:50 [scrapy] INFO: Overridden settings: {'NEWSPIDER_MODULE': 'totalcorner.spiders', 'SPIDER_MODULES': ['totalcorner.spiders'], 'BOT_NAME': 'totalcorner'}
    2016-08-17 17:20:50 [scrapy] INFO: Enabled extensions:
    ['scrapy.extensions.logstats.LogStats',
     'scrapy.extensions.telnet.TelnetConsole',
     'scrapy.extensions.corestats.CoreStats']
    2016-08-17 17:20:50 [scrapy] INFO: Enabled downloader middlewares:
    ['scrapy.downloadermiddlewares.httpauth.HttpAuthMiddleware',
     'scrapy.downloadermiddlewares.downloadtimeout.DownloadTimeoutMiddleware',
     'scrapy.downloadermiddlewares.useragent.UserAgentMiddleware',
     'scrapy.downloadermiddlewares.retry.RetryMiddleware',
     'scrapy.downloadermiddlewares.defaultheaders.DefaultHeadersMiddleware',
     'scrapy.downloadermiddlewares.redirect.MetaRefreshMiddleware',
     'scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware',
     'scrapy.downloadermiddlewares.redirect.RedirectMiddleware',
     'scrapy.downloadermiddlewares.cookies.CookiesMiddleware',
     'scrapy.downloadermiddlewares.chunked.ChunkedTransferMiddleware',
     'scrapy.downloadermiddlewares.stats.DownloaderStats']
    2016-08-17 17:20:50 [scrapy] INFO: Enabled spider middlewares:
    ['scrapy.spidermiddlewares.httperror.HttpErrorMiddleware',
     'scrapy.spidermiddlewares.offsite.OffsiteMiddleware',
     'scrapy.spidermiddlewares.referer.RefererMiddleware',
     'scrapy.spidermiddlewares.urllength.UrlLengthMiddleware',
     'scrapy.spidermiddlewares.depth.DepthMiddleware']
    2016-08-17 17:20:50 [scrapy] INFO: Enabled item pipelines:
    []
    2016-08-17 17:20:50 [scrapy] INFO: Spider opened
    2016-08-17 17:20:50 [scrapy] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
    2016-08-17 17:20:50 [scrapy] DEBUG: Telnet console listening on 127.0.0.1:6023
    2016-08-17 17:20:53 [scrapy] DEBUG: Crawled (200) <GET http://www.totalcorner.com/match/corner_stats/57838664> (referer: None)
    2016-08-17 17:20:53 [scrapy] INFO: Closing spider (finished)
    2016-08-17 17:20:53 [scrapy] INFO: Dumping Scrapy stats:
    {'downloader/request_bytes': 244,
     'downloader/request_count': 1,
     'downloader/request_method_count/GET': 1,
     'downloader/response_bytes': 5541,
     'downloader/response_count': 1,
     'downloader/response_status_count/200': 1,
     'finish_reason': 'finished',
     'finish_time': datetime.datetime(2016, 8, 17, 9, 20, 53, 487371),
     'log_count/DEBUG': 2,
     'log_count/INFO': 7,
     'response_received_count': 1,
     'scheduler/dequeued': 1,
     'scheduler/dequeued/memory': 1,
     'scheduler/enqueued': 1,
     'scheduler/enqueued/memory': 1,
     'start_time': datetime.datetime(2016, 8, 17, 9, 20, 50, 660260)}
    2016-08-17 17:20:53 [scrapy] INFO: Spider closed (finished)

1 个答案:

答案 0 :(得分:0)

我找到了原因,这是一个愚蠢的错误。蜘蛛的文件名应为totalcorner_spider.py。我的错。谢谢你的努力。