Scrapy spider Crawls 0页

7gyucuyw  于 2023-03-30  发布在  其他
关注(0)|答案(1)|浏览(126)

谢谢大家看!真的很感激任何帮助。
this教程scrapy基础知识.我的蜘蛛似乎没有返回任何东西,因此,csv文件是空的.下面,我已经粘贴了蜘蛛代码,和我在终端接收的消息.从教程中的一切之前,蜘蛛不工作,即运行'scrapy shell'并使用CSS选择器获取信息片段。请注意,只有当我运行没有''的scrapy shell命令时,这些命令才有效。我在Windows上,在虚拟环境中工作。

蜘蛛码

import scrapy

class DronesspiderSpider(scrapy.Spider):
    name = 'dronesspider'
    allowed_domains = ['jessops.com/drones']
    start_urls = ['http://jessops.com/drones/']

    def parse(self, response):
        products = response.css('div.details-pricing')
        for product in products:
            item = {
            'name' : product.css('a::text').get(),
            'price' : product.css('p.price.larger::text').get()
            }
            yield item
        pass

终端返回消息

(venv) C:\Users\User\drones>scrapy crawl dronesspider -o drones.csv --set="ROBOTSTXT_OBEY=False"
2023-03-24 10:04:07 [scrapy.utils.log] INFO: Scrapy 2.8.0 started (bot: drones)
2023-03-24 10:04:07 [scrapy.utils.log] INFO: Versions: lxml 4.9.2.0, libxml2 2.9.12, cssselect 1.2.0, parsel 1.7.0, w3lib 2.1.1, Twisted 22.10.0, Python 3.10.10 (tags/v3.10.10:aad5f6a, Feb  7 2023, 17:20:36) [MSC v.1929 64 bit (AMD64)], pyOpenSSL 23.0.0 (OpenSSL 3.0.8 7 Feb 2023), cryptography 39.0.2, Platform Windows-10-10.0.19045-SP0
2023-03-24 10:04:07 [scrapy.crawler] INFO: Overridden settings:
{'BOT_NAME': 'drones',
 'FEED_EXPORT_ENCODING': 'utf-8',
 'NEWSPIDER_MODULE': 'drones.spiders',
 'REQUEST_FINGERPRINTER_IMPLEMENTATION': '2.7',
 'ROBOTSTXT_OBEY': 'False',
 'SPIDER_MODULES': ['drones.spiders'],
 'TWISTED_REACTOR': 'twisted.internet.asyncioreactor.AsyncioSelectorReactor'}
2023-03-24 10:04:07 [asyncio] DEBUG: Using selector: SelectSelector
2023-03-24 10:04:07 [scrapy.utils.log] DEBUG: Using reactor: twisted.internet.asyncioreactor.AsyncioSelectorReactor
2023-03-24 10:04:07 [scrapy.utils.log] DEBUG: Using asyncio event loop: asyncio.windows_events._WindowsSelectorEventLoop
2023-03-24 10:04:07 [scrapy.extensions.telnet] INFO: Telnet Password: ec95e674fcfc2fd5
2023-03-24 10:04:07 [scrapy.middleware] INFO: Enabled extensions:
['scrapy.extensions.corestats.CoreStats',
 'scrapy.extensions.telnet.TelnetConsole',
 'scrapy.extensions.feedexport.FeedExporter',
 'scrapy.extensions.logstats.LogStats']
2023-03-24 10:04:08 [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']
2023-03-24 10:04:08 [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']
2023-03-24 10:04:08 [scrapy.middleware] INFO: Enabled item pipelines:
[]
2023-03-24 10:04:08 [scrapy.core.engine] INFO: Spider opened
2023-03-24 10:04:08 [scrapy.extensions.logstats] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2023-03-24 10:04:08 [scrapy.extensions.telnet] INFO: Telnet console listening on 127.0.0.1:6023
2023-03-24 10:04:09 [scrapy.downloadermiddlewares.redirect] DEBUG: Redirecting (301) to <GET https://jessops.com/> from <GET http://jessops.com/>
2023-03-24 10:04:09 [scrapy.downloadermiddlewares.redirect] DEBUG: Redirecting (301) to <GET https://www.jessops.com/> from <GET https://jessops.com/>
2023-03-24 10:04:09 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://www.jessops.com/> (referer: None)
2023-03-24 10:04:09 [scrapy.core.engine] INFO: Closing spider (finished)
2023-03-24 10:04:09 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 637,
 'downloader/request_count': 3,
 'downloader/request_method_count/GET': 3,
 'downloader/response_bytes': 24758,
 'downloader/response_count': 3,
 'downloader/response_status_count/200': 1,
 'downloader/response_status_count/301': 2,
 'elapsed_time_seconds': 0.406225,
 'finish_reason': 'finished',
 'finish_time': datetime.datetime(2023, 3, 24, 10, 4, 9, 336667),
 'httpcompression/response_bytes': 128442,
 'httpcompression/response_count': 1,
 'log_count/DEBUG': 6,
 'log_count/INFO': 10,
 'response_received_count': 1,
 'scheduler/dequeued': 3,
 'scheduler/dequeued/memory': 3,
 'scheduler/enqueued': 3,
 'scheduler/enqueued/memory': 3,
 'start_time': datetime.datetime(2023, 3, 24, 10, 4, 8, 930442)}
2023-03-24 10:04:09 [scrapy.core.engine] INFO: Spider closed (finished)

尝试
1.将robotstxt_obey设置为false
1.更改URL
1.将URL中的“to”更改为“none
以上都没有对输出进行任何更改

fae0ux8s

fae0ux8s1#

解决了。原来我在dronesspider.py虚拟环境文件夹中有2个www.example.com文件。在“spiders”文件夹中的那个是正在运行的,第二个是我正在工作的那个。删除了第二个并更新了第一个,现在它正在工作。

相关问题