hsq_dbzsl 2022-05-06 00:26 采纳率: 50%
浏览 338
已结题

爬虫scrapy框架爬不出来,但是request可以出来

爬虫scrapy框架爬不出来,但是request可以出来,能不能帮忙看一下问题遇到的现象和发生背景

from scrapy.spiders import CrawlSpider
from scrapy.selector import Selector
from  scrapy.http import Request
from zhuanti.items import ZhuantiItem
class zhuanti(CrawlSpider):
    name = 'zhuanti'
    start_urls=['https://www.jianshu.com/recommendations/collections?page=1&order_by=hot']

    def parse(self,response):
        item=ZhuantiItem()
        selector=Selector(response)
        infos=selector.xpath('//div[@class="col-xs-8"]')
        for info in infos:
            try:
                name=info.xpath('//div/a/h4/text()').extract()[0]
                content=info.xpath('//div/a/p/text()').extract()[0]
                article=info.xpath('//div/div/a/text()').extract()[0]
                fans = info.xpath('//div/div/text()').extract()[0]

                item['name']=name
                item['content'] = content
                item['article'] = article
                item['fans'] = fans

                yield item
            except IndexError:
                pass

        urls=['https://www.jianshu.com/recommendations/collections?page={}&order_by=hot'.format(str(a))for a in range(2,39)]
        for url in urls:
            yield Request(url,callback=self.parse)

settings:
USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36'
ROBOTSTXT_OBEY = False
FEED_URI='file:D:\AppStore\zhuanti.csv'
FEED_FORMAT='csv'

报错

2022-05-06 00:02:02 [scrapy.utils.log] INFO: Scrapy 2.6.1 started (bot: zhuanti)
2022-05-06 00:02:02 [scrapy.utils.log] INFO: Versions: lxml 4.6.3.0, libxml2 2.9.5, cssselect 1.1.0, parsel 1.6.0, w3lib 1.22.0, Twisted 20.3.0, Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)], pyOpenSSL 22.0.0 (OpenSSL 1.1.1n  15 Mar 2022), cryptography 36.0.2, Platform Windows-10-10.0.19041-SP0
2022-05-06 00:02:02 [scrapy.crawler] INFO: Overridden settings:
{'BOT_NAME': 'zhuanti',
 'DOWNLOAD_DELAY': 0.5,
 'NEWSPIDER_MODULE': 'zhuanti.spiders',
 'SPIDER_MODULES': ['zhuanti.spiders'],
 'USER_AGENT': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '
               '(KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36'}
2022-05-06 00:02:02 [scrapy.utils.log] DEBUG: Using reactor: twisted.internet.selectreactor.SelectReactor
2022-05-06 00:02:02 [scrapy.extensions.telnet] INFO: Telnet Password: 8d77413cfb4deb45
2022-05-06 00:02:02 [py.warnings] WARNING: C:\Users\86159\PycharmProjects\untitled2\venv\lib\site-packages\scrapy\extensions\feedexport.py:289: ScrapyDeprecationWarning: The `FEED_URI` and `FEED_FORMAT` settings have been deprecated in favor of the `FEEDS` setting. Please see the `FEEDS` setting docs for more details
  exporter = cls(crawler)

2022-05-06 00:02:02 [scrapy.middleware] INFO: Enabled extensions:
['scrapy.extensions.corestats.CoreStats',
 'scrapy.extensions.telnet.TelnetConsole',
 'scrapy.extensions.feedexport.FeedExporter',
 'scrapy.extensions.logstats.LogStats']
2022-05-06 00:02:02 [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']
2022-05-06 00:02:02 [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']
2022-05-06 00:02:02 [scrapy.middleware] INFO: Enabled item pipelines:
[]
2022-05-06 00:02:02 [scrapy.core.engine] INFO: Spider opened
2022-05-06 00:02:02 [scrapy.extensions.logstats] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2022-05-06 00:02:02 [scrapy.extensions.telnet] INFO: Telnet console listening on 127.0.0.1:6023
2022-05-06 00:02:14 [filelock] DEBUG: Attempting to acquire lock 1699218188328 on C:\Users\86159\PycharmProjects\untitled2\venv\lib\site-packages\tldextract\.suffix_cache/publicsuffix.org-tlds\de84b5ca2167d4c83e38fb162f2e8738.tldextract.json.lock
2022-05-06 00:02:14 [filelock] DEBUG: Lock 1699218188328 acquired on C:\Users\86159\PycharmProjects\untitled2\venv\lib\site-packages\tldextract\.suffix_cache/publicsuffix.org-tlds\de84b5ca2167d4c83e38fb162f2e8738.tldextract.json.lock
2022-05-06 00:02:14 [filelock] DEBUG: Attempting to acquire lock 1699218187824 on C:\Users\86159\PycharmProjects\untitled2\venv\lib\site-packages\tldextract\.suffix_cache/urls\62bf135d1c2f3d4db4228b9ecaf507a2.tldextract.json.lock
2022-05-06 00:02:14 [filelock] DEBUG: Lock 1699218187824 acquired on C:\Users\86159\PycharmProjects\untitled2\venv\lib\site-packages\tldextract\.suffix_cache/urls\62bf135d1c2f3d4db4228b9ecaf507a2.tldextract.json.lock
2022-05-06 00:02:14 [filelock] DEBUG: Attempting to release lock 1699218187824 on C:\Users\86159\PycharmProjects\untitled2\venv\lib\site-packages\tldextract\.suffix_cache/urls\62bf135d1c2f3d4db4228b9ecaf507a2.tldextract.json.lock
2022-05-06 00:02:14 [filelock] DEBUG: Lock 1699218187824 released on C:\Users\86159\PycharmProjects\untitled2\venv\lib\site-packages\tldextract\.suffix_cache/urls\62bf135d1c2f3d4db4228b9ecaf507a2.tldextract.json.lock
2022-05-06 00:02:14 [filelock] DEBUG: Attempting to release lock 1699218188328 on C:\Users\86159\PycharmProjects\untitled2\venv\lib\site-packages\tldextract\.suffix_cache/publicsuffix.org-tlds\de84b5ca2167d4c83e38fb162f2e8738.tldextract.json.lock
2022-05-06 00:02:14 [filelock] DEBUG: Lock 1699218188328 released on C:\Users\86159\PycharmProjects\untitled2\venv\lib\site-packages\tldextract\.suffix_cache/publicsuffix.org-tlds\de84b5ca2167d4c83e38fb162f2e8738.tldextract.json.lock
2022-05-06 00:02:14 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://www.jianshu.com/recommendations/collections?page=1&order_by=hot> (referer: None)
2022-05-06 00:02:14 [scrapy.core.engine] INFO: Closing spider (finished)
2022-05-06 00:02:14 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 282,
 'downloader/request_count': 1,
 'downloader/request_method_count/GET': 1,
 'downloader/response_bytes': 9105,
 'downloader/response_count': 1,
 'downloader/response_status_count/200': 1,
 'elapsed_time_seconds': 11.793553,
 'finish_reason': 'finished',
 'finish_time': datetime.datetime(2022, 5, 5, 16, 2, 14, 359618),
 'httpcompression/response_bytes': 26418,
 'httpcompression/response_count': 1,
 'log_count/DEBUG': 10,
 'log_count/INFO': 10,
 '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(2022, 5, 5, 16, 2, 2, 566065)}
2022-05-06 00:02:14 [scrapy.core.engine] INFO: Spider closed (finished)



大家看看能不能解决一下

  • 写回答

2条回答 默认 最新

  • keenanli 2022-05-06 07:46
    关注

    你应该继承 scrapy.Spider
    CrawlSpider 不要自定义 parse 函数。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 5月14日
  • 已采纳回答 5月6日
  • 赞助了问题酬金5元 5月6日
  • 创建了问题 5月6日

悬赏问题

  • ¥50 WPF Lidgren.Network.Core2连接问题
  • ¥15 soildworks装配体的尺寸问题
  • ¥100 有偿寻云闪付SDK转URL技术
  • ¥30 基于信创PC发布的QT应用如何跨用户启动后输入中文
  • ¥20 非root手机,如何精准控制手机流量消耗的大小,如20M
  • ¥15 远程安装一下vasp
  • ¥15 自己做的代码上传图片时,报错
  • ¥15 Lingo线性规划模型怎么搭建
  • ¥15 关于#python#的问题,请各位专家解答!区间型正向化
  • ¥15 unity从3D升级到urp管线,打包ab包后,材质全部变紫色