没有页面在scrapy中被抓取

时间:2015-09-03 19:57:30

标签: python web-scraping scrapy

我在Scrapy中有以下蜘蛛用于从eBay.com抓取和保存网页,用于防晒太阳镜

import scrapy
from scrapy.spiders import CrawlSpider, Rule
from scrapy.linkextractors import LinkExtractor

class EbaySpider(CrawlSpider):
    name = 'ebay'
    allowed_domains = ['ebay.com']
    start_urls = ['http://www.ebay.com',
        'http://www.ebay.com/sch/i.html?_from=R40&_trksid=p2050601.m570.l1312.R1.TR11.TRC2.A0.H0.Xray.TRS1&_nkw=ray+ban+sunglasses&_sacat=0'
    ]

    rules = [
        Rule(LinkExtractor(allow=[r'itm/.*ray.*ban.*sunglassses']), follow='true', callback='parse_item')
    ]    

    def parse_item(self, response):
        filename = response.url.split("/")[-2] + '.html'
        with open(filename, 'wb') as f:
            f.write(response.body)

这是我得到的输出:

INFO: Enabled item pipelines: 
2015-09-03 12:50:11 [scrapy] INFO: Spider opened
2015-09-03 12:50:11 [scrapy] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2015-09-03 12:50:11 [scrapy] DEBUG: Telnet console listening on 127.0.0.1:6023
2015-09-03 12:50:12 [scrapy] DEBUG: Crawled (200) <GET 

http://www.ebay.com> (referer: None)
    2015-09-03 12:50:12 [scrapy] INFO: Closing spider (finished)
    2015-09-03 12:50:12 [scrapy] INFO: Dumping Scrapy stats:
    {'downloader/request_bytes': 210,
     'downloader/request_count': 1,
     'downloader/request_method_count/GET': 1,
     'downloader/response_bytes': 25707,
     'downloader/response_count': 1,
'downloader/response_status_count/200': 1,
 'finish_reason': 'finished',
 'finish_time': datetime.datetime(2015, 9, 3, 19, 50, 12, 755020),
 'log_count/DEBUG': 2,
 'log_count/INFO': 7,
 'log_count/WARNING': 1,
 'response_received_count': 1,
 'scheduler/dequeued': 1,
 'scheduler/dequeued/memory': 1,
 'scheduler/enqueued': 1,
 'scheduler/enqueued/memory': 1,
 'start_time': datetime.datetime(2015, 9, 3, 19, 50, 11, 809426)}
2015-09-03 12:50:12 [scrapy] INFO: Spider closed (finished)

有人可以指出出了什么问题吗?我是一个擦伤的小伙子。

1 个答案:

答案 0 :(得分:1)

页面上没有任何内容与字符串Runtime.getRuntime().exec("echo 1 > /dev/ttyACM0"); 中的正则表达式匹配。您可以通过启动指向start_url的shell来执行此操作,并执行以下操作:

r'itm/.*ray.*ban.*sunglassses'

首先,为了让它摆脱困境(它是罪魁祸首),是#34;太阳镜&#34; (你有三个&#39;)。

其次,默认情况下,正则表达式区分大小写,因此>>> from scrapy.linkextractor import LinkExtractor >>> LinkExtractor(allow=[r'itm/.*ray.*ban.*sunglassses']).extract_links(response) [] 不会匹配包含&#34; Ray-ban&#34;的链接。或者&#34; Ray Ban&#34;。要更正此问题,请使用r'ray.*ban'标记预编译正则表达式,并将其传递给链接提取器。

IGNORECASE