scrapy 不能提取下一页

发布于 2022-09-11 17:53:10 字数 3935 浏览 18 评论 0

问题描述

不能获取下一页

相关代码

// 请把代码文本粘贴到下方(请勿用图片代替代码)

import scrapy
from qsbk.items import QsbkItem
from scrapy.http.response.html import HtmlResponse
from scrapy.selector.unified import SelectorList

class QsbkSpiderSpider(scrapy.Spider):

name = 'qsbk_spider'
allowed_domains = ['qiushibaike.com']
start_urls = ['https://www.qiushibaike.com/text/page/1/']
base_domain = 'https://www.qiushibaike.com/'

def parse(self, response):
    duanzidivs = response.xpath("//div[@id='content-left']/div")
    for duanzidiv in duanzidivs:
        author = duanzidiv.xpath(".//h2/text()").get().strip()
        content = duanzidiv.xpath(".//div[@class='content']//text()").getall()
        content = "".join(content).strip()

        item = QsbkItem(author=author,content=content)
        yield item

    next_url = response.xpath("//ul[@class='pagination']/li[last()]/a/@href").get()
    if not next_url:
        return
    else:
        yield scrapy.Request(self.base_domain+next_url,callback=self.parse)

从这里开始发生错误,前一个页面正常提取,到第二页就发生错误了?

2019-02-23 14:07:32 [scrapy.downloadermiddlewares.redirect] DEBUG: Redirecting (301) to <GET https://text/&gt; from <GET https://www.qiushibaike.com//...;
2019-02-23 14:07:35 [scrapy.downloadermiddlewares.retry] DEBUG: Retrying <GET https://text/&gt; (failed 1 times): DNS lookup failed: no results for hostname lookup: text.
2019-02-23 14:07:37 [scrapy.downloadermiddlewares.retry] DEBUG: Retrying <GET https://text/&gt; (failed 2 times): DNS lookup failed: no results for hostname lookup: text.
2019-02-23 14:07:40 [scrapy.downloadermiddlewares.retry] DEBUG: Gave up retrying <GET https://text/&gt; (failed 3 times): DNS lookup failed: no results for hostname lookup: text.
2019-02-23 14:07:40 [scrapy.core.scraper] ERROR: Error downloading <GET https://text/&gt;
Traceback (most recent call last):
File "D:venvarticle_spiderlibsite-packagestwistedinternetdefer.py", line 1416, in _inlineCallbacks

result = result.throwExceptionIntoGenerator(g)

File "D:venvarticle_spiderlibsite-packagestwistedpythonfailure.py", line 491, in throwExceptionIntoGenerator

return g.throw(self.type, self.value, self.tb)

File "D:venvarticle_spiderlibsite-packagesscrapycoredownloadermiddleware.py", line 43, in process_request

defer.returnValue((yield download_func(request=request,spider=spider)))

File "D:venvarticle_spiderlibsite-packagestwistedinternetdefer.py", line 654, in _runCallbacks

current.result = callback(current.result, *args, **kw)

File "D:venvarticle_spiderlibsite-packagestwistedinternetendpoints.py", line 975, in startConnectionAttempts

"no results for hostname lookup: {}".format(self._hostStr)

twisted.internet.error.DNSLookupError: DNS lookup failed: no results for hostname lookup: text.

问题描述

问题出现的平台版本及自己尝试过哪些方法

相关代码

// 请把代码文本粘贴到下方(请勿用图片代替代码)

你期待的结果是什么?实际看到的错误信息又是什么?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文