m0_49938637 2021-09-05 19:18 采纳率: 100%
浏览 120
已结题

在以瀑布流方式翻页的网站,使用scrapy网络爬虫,但是只爬取了第一页数据,没有爬取第二页.

import scrapy

from news.items import NewsItem


# https://www.gelonghui.com/api/channels/web_home_page/articles/v8?timestamp=1630749332&loaded=15

class AbcSpider(scrapy.Spider):
    name = 'abc'
    allowed_domains = ['gelonghui.com']
    start_urls = ['http://gelonghui.com']

    def parse(self, response):
        item = NewsItem()
        elements = response.css('.detail-right')

        for element in elements:
            item['title'] = element.css('h2::text').extract_first()
            yield item

        url_ajax = 'https://www.gelonghui.com/api/channels/web_home_page/articles/v8?'
        data = {
            'timestamp': '1630749332',
            'loaded': '15'
        }
        yield scrapy.FormRequest(url=url_ajax,
                                 method='get',
                                 formdata=data,
                                 dont_filter=True,
                                 callback=self.parse)


2021-09-05 19:17:05 [scrapy.utils.log] INFO: Scrapy 2.5.0 started (bot: news)
2021-09-05 19:17:05 [scrapy.utils.log] INFO: Versions: lxml 4.6.3.0, libxml2 2.9.4, cssselect 1.1.0, parsel 1.6.0, w3lib 1.22.0, Twisted 21.2.0, Python 3.9.1 (v3.9.1:1e5d33e9b9, Dec  7 2020, 12:44:01) - [Clang 12.0.0 (clang-1200.0.32.27)], pyOpenSSL 20.0.1 (OpenSSL 1.1.1l  24 Aug 2021), cryptography 3.4.8, Platform macOS-11.5.2-x86_64-i386-64bit
2021-09-05 19:17:05 [scrapy.utils.log] DEBUG: Using reactor: twisted.internet.selectreactor.SelectReactor
2021-09-05 19:17:05 [scrapy.crawler] INFO: Overridden settings:
{'BOT_NAME': 'news',
 'NEWSPIDER_MODULE': 'news.spiders',
 'ROBOTSTXT_OBEY': True,
 'SPIDER_MODULES': ['news.spiders'],
 'USER_AGENT': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) '
               'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 '
               'Safari/537.36'}
2021-09-05 19:17:05 [scrapy.extensions.telnet] INFO: Telnet Password: 8ec24b696530a0ca
2021-09-05 19:17:05 [scrapy.middleware] INFO: Enabled extensions:
['scrapy.extensions.corestats.CoreStats',
 'scrapy.extensions.telnet.TelnetConsole',
 'scrapy.extensions.memusage.MemoryUsage',
 'scrapy.extensions.logstats.LogStats']
2021-09-05 19:17:05 [scrapy.middleware] INFO: Enabled downloader middlewares:
['scrapy.downloadermiddlewares.robotstxt.RobotsTxtMiddleware',
 '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']
2021-09-05 19:17:05 [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']
2021-09-05 19:17:05 [scrapy.middleware] INFO: Enabled item pipelines:
[]
2021-09-05 19:17:05 [scrapy.core.engine] INFO: Spider opened
2021-09-05 19:17:05 [scrapy.extensions.logstats] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2021-09-05 19:17:05 [scrapy.extensions.telnet] INFO: Telnet console listening on 127.0.0.1:6023
2021-09-05 19:17:05 [scrapy.downloadermiddlewares.redirect] DEBUG: Redirecting (301) to <GET https://gelonghui.com/robots.txt> from <GET http://gelonghui.com/robots.txt>
2021-09-05 19:17:05 [scrapy.downloadermiddlewares.redirect] DEBUG: Redirecting (301) to <GET https://www.gelonghui.com/robots.txt> from <GET https://gelonghui.com/robots.txt>
2021-09-05 19:17:05 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://www.gelonghui.com/robots.txt> (referer: None)
2021-09-05 19:17:06 [scrapy.downloadermiddlewares.redirect] DEBUG: Redirecting (301) to <GET https://gelonghui.com/> from <GET http://gelonghui.com>
2021-09-05 19:17:06 [scrapy.downloadermiddlewares.redirect] DEBUG: Redirecting (301) to <GET https://www.gelonghui.com/> from <GET https://gelonghui.com/>
2021-09-05 19:17:06 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://www.gelonghui.com/robots.txt> (referer: None)
2021-09-05 19:17:06 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://www.gelonghui.com/> (referer: None)
2021-09-05 19:17:06 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.gelonghui.com/>
{'title': '元宇宙,人类最后的迁徙'}
2021-09-05 19:17:06 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.gelonghui.com/>
{'title': 'Jackson Hole后的美联储货币政策冷思考:预期引导or相机抉择'}
2021-09-05 19:17:06 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.gelonghui.com/>
{'title': '重磅!北交所上市、交易等三大规则来了!七大要点看这里!'}
2021-09-05 19:17:06 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.gelonghui.com/>
{'title': '短空是多短,长多又是多长'}
2021-09-05 19:17:06 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.gelonghui.com/>
{'title': '广发郭磊:九问九答宏观经济'}
2021-09-05 19:17:06 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.gelonghui.com/>
{'title': '房地产经济近况如何?'}
2021-09-05 19:17:06 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.gelonghui.com/>
{'title': '美国50年公平与效率摇摆史的产业启示'}
2021-09-05 19:17:06 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.gelonghui.com/>
{'title': '宋雪涛:宏观研究需要新范式'}
2021-09-05 19:17:06 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.gelonghui.com/>
{'title': '机构席位大宗交易活跃度下降,这些个股却被大幅扫货……'}
2021-09-05 19:17:06 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.gelonghui.com/>
{'title': '永安依旧“最赚钱”,混沌天成“栽了跟头”!73家期货公司上半年业绩出炉,净利最高暴增1368.68%'}
2021-09-05 19:17:06 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.gelonghui.com/>
{'title': '大动作!微信聊天记录付费云存储?苹果每年180元,安卓130元,你会买单吗?'}
2021-09-05 19:17:06 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.gelonghui.com/>
{'title': '能源新基建:绿色复苏新路径'}
2021-09-05 19:17:06 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.gelonghui.com/>
{'title': '食品饮料是如何从天堂到地狱的——速食&休闲篇'}
2021-09-05 19:17:06 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.gelonghui.com/>
{'title': '多部委透露新能源汽车重大政策动向:进一步提高锂、钴、镍保障体系'}
2021-09-05 19:17:06 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.gelonghui.com/>
{'title': '人工钻石的疯狂上位之路'}
2021-09-05 19:17:06 [scrapy.downloadermiddlewares.robotstxt] DEBUG: Forbidden by robots.txt: <GET https://www.gelonghui.com/api/channels/web_home_page/articles/v8?timestamp=1630749332&loaded=15>
2021-09-05 19:17:06 [scrapy.core.engine] INFO: Closing spider (finished)
2021-09-05 19:17:06 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{'downloader/exception_count': 1,
 'downloader/exception_type_count/scrapy.exceptions.IgnoreRequest': 1,
 'downloader/request_bytes': 2257,
 'downloader/request_count': 7,
 'downloader/request_method_count/GET': 7,
 'downloader/response_bytes': 71423,
 'downloader/response_count': 7,
 'downloader/response_status_count/200': 3,
 'downloader/response_status_count/301': 4,
 'elapsed_time_seconds': 0.928904,
 'finish_reason': 'finished',
 'finish_time': datetime.datetime(2021, 9, 5, 11, 17, 6, 584573),
 'httpcompression/response_bytes': 313699,
 'httpcompression/response_count': 3,
 'item_scraped_count': 15,
 'log_count/DEBUG': 23,
 'log_count/INFO': 10,
 'memusage/max': 222773248,
 'memusage/startup': 222773248,
 'request_depth_max': 1,
 'response_received_count': 3,
 'robotstxt/forbidden': 1,
 'robotstxt/request_count': 2,
 'robotstxt/response_count': 2,
 'robotstxt/response_status_count/200': 2,
 'scheduler/dequeued': 4,
 'scheduler/dequeued/memory': 4,
 'scheduler/enqueued': 4,
 'scheduler/enqueued/memory': 4,
 'start_time': datetime.datetime(2021, 9, 5, 11, 17, 5, 655669)}
2021-09-05 19:17:06 [scrapy.core.engine] INFO: Spider closed (finished)


> 
> 
> 
> 
> 

  • 写回答

2条回答 默认 最新

  • Mint.Coder 2021-09-05 20:31
    关注

    那叫ajax,

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

报告相同问题?

问题事件

  • 系统已结题 9月14日
  • 已采纳回答 9月6日
  • 创建了问题 9月5日

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站