欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

爬虫没有数据结果

程序员文章站 2022-07-12 12:58:56
...

爬虫没有数据结果

小白学python爬虫,使用scrapy框架进行爬取网站数据,遇到爬取数据的时候没有返回的结果,代码是根据视频里的老师敲的,看着挺简单的一个程序,网上看了很多方法都没解决,求大神帮助。

这是代码

#-- coding: utf-8 --
import scrapy
from scrapy.http.response.html import HtmlResponse
from scrapy.selector.unified import SelectorList

class SpiderDxysSpider(scrapy.Spider):
name = ‘spider_dxys’
allowed_domains = [‘dxy.com/search/health’]
start_urls = [f’https://dxy.com/view/i/recommend/referral/list?{page_index}&items_per_page=5&q=%E6%8A%91%E9%83%81%E7%97%87&spell_check=false&postcode=000001/’ for page_index in range(1,6)]

def parse(self, response):
    # selectorList
    hospitaldivs=response.xpath("//div[@id='comment-item']/div")
    # hospitaldivs = response.xpath('.//div')
    #     Selector
    for hospitaldiv in hospitaldivs:
        hospital = hospitaldiv.xpath(".//p/text()").getall()
        print(hospital)

这是返回的信息

2020-03-11 18:20:10 [scrapy.utils.log] INFO: Scrapy 1.6.0 started (bot: yiyu)
2020-03-11 18:20:10 [scrapy.utils.log] INFO: Versions: lxml 4.4.1.0, libxml2 2.9.9, cssselect 1.1.0, parsel 1.5.2, w3lib 1.21.0, Twisted 19.10.0, Python 3.7.4 (default, Aug 9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)], pyOpenSSL 19.0.0 (OpenSSL 1.1.1d 10 Sep 2019), cryptography 2.7, Platform Windows-10-10.0.17763-SP0
2020-03-11 18:20:10 [scrapy.crawler] INFO: Overridden settings: {‘BOT_NAME’: ‘yiyu’, ‘NEWSPIDER_MODULE’: ‘yiyu.spiders’, ‘SPIDER_MODULES’: [‘yiyu.spiders’]}
2020-03-11 18:20:10 [scrapy.extensions.telnet] INFO: Telnet Password: ec002cef1ec1b96b
2020-03-11 18:20:10 [scrapy.middleware] INFO: Enabled extensions:
[‘scrapy.extensions.corestats.CoreStats’,
‘scrapy.extensions.telnet.TelnetConsole’,
‘scrapy.extensions.logstats.LogStats’]
2020-03-11 18:20:12 [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’]
2020-03-11 18:20:12 [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’]
2020-03-11 18:20:12 [scrapy.middleware] INFO: Enabled item pipelines:
[]
2020-03-11 18:20:12 [scrapy.core.engine] INFO: Spider opened
2020-03-11 18:20:12 [scrapy.extensions.logstats] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2020-03-11 18:20:12 [scrapy.extensions.telnet] INFO: Telnet console listening on 127.0.0.1:6023
2020-03-11 18:20:12 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://dxy.com/view/i/recommend/referral/list?3&items_per_page=5&q=%E6%8A%91%E9%83%81%E7%97%87&spell_check=false&postcode=000001/> (referer: None)
2020-03-11 18:20:12 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://dxy.com/view/i/recommend/referral/list?2&items_per_page=5&q=%E6%8A%91%E9%83%81%E7%97%87&spell_check=false&postcode=000001/> (referer: None)
2020-03-11 18:20:12 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://dxy.com/view/i/recommend/referral/list?1&items_per_page=5&q=%E6%8A%91%E9%83%81%E7%97%87&spell_check=false&postcode=000001/> (referer: None)
2020-03-11 18:20:12 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://dxy.com/view/i/recommend/referral/list?4&items_per_page=5&q=%E6%8A%91%E9%83%81%E7%97%87&spell_check=false&postcode=000001/> (referer: None)
2020-03-11 18:20:12 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://dxy.com/view/i/recommend/referral/list?5&items_per_page=5&q=%E6%8A%91%E9%83%81%E7%97%87&spell_check=false&postcode=000001/> (referer: None)
2020-03-11 18:20:12 [scrapy.core.engine] INFO: Closing spider (finished)
2020-03-11 18:20:12 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{‘downloader/request_bytes’: 2005,
‘downloader/request_count’: 5,
‘downloader/request_method_count/GET’: 5,
‘downloader/response_bytes’: 9105,
‘downloader/response_count’: 5,
‘downloader/response_status_count/200’: 5,
‘finish_reason’: ‘finished’,
‘finish_time’: datetime.datetime(2020, 3, 11, 10, 20, 12, 756517),
‘log_count/DEBUG’: 5,
‘log_count/INFO’: 9,
‘response_received_count’: 5,
‘scheduler/dequeued’: 5,
‘scheduler/dequeued/memory’: 5,
‘scheduler/enqueued’: 5,
‘scheduler/enqueued/memory’: 5,
‘start_time’: datetime.datetime(2020, 3, 11, 10, 20, 12, 67624)}
2020-03-11 18:20:12 [scrapy.core.engine] INFO: Spider closed (finished)

Process finished with exit code 0