爬虫Scrapy框架项目运行时报错!求解决!

E:\JetBrains\PyCharm\mySpider>scrapy crawl itcast -o itcast.json
2018-03-26 14:50:23 [scrapy.utils.log] INFO: Scrapy 1.5.0 started (bot: mySpider)
2018-03-26 14:50:23 [scrapy.utils.log] INFO: Versions: lxml 4.2.1.0, libxml2 2.9.5, cssselect 1.0.3, parsel 1.4.0, w3lib
 1.19.0, Twisted 17.9.0, Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)], pyOpenSSL 17.
5.0 (OpenSSL 1.1.0g  2 Nov 2017), cryptography 2.2.1, Platform Windows-10-10.0.16299-SP0
2018-03-26 14:50:23 [scrapy.crawler] INFO: Overridden settings: {'BOT_NAME': 'mySpider', 'FEED_FORMAT': 'json', 'FEED_UR
I': 'itcast.json', 'NEWSPIDER_MODULE': 'mySpider.spiders', 'SPIDER_MODULES': ['mySpider.spiders']}
2018-03-26 14:50:23 [scrapy.middleware] INFO: Enabled extensions:
['scrapy.extensions.corestats.CoreStats',
 'scrapy.extensions.telnet.TelnetConsole',
 'scrapy.extensions.feedexport.FeedExporter',
 'scrapy.extensions.logstats.LogStats']
2018-03-26 14:50:23 [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']
2018-03-26 14:50:23 [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']
2018-03-26 14:50:23 [scrapy.middleware] INFO: Enabled item pipelines:
[]
2018-03-26 14:50:23 [scrapy.core.engine] INFO: Spider opened
2018-03-26 14:50:23 [scrapy.extensions.logstats] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min
)
2018-03-26 14:50:23 [scrapy.extensions.telnet] DEBUG: Telnet console listening on 127.0.0.1:6023
2018-03-26 14:50:33 [scrapy.downloadermiddlewares.retry] DEBUG: Retrying > (failed 1 times): Connection was refused by other side: 10061: 由于目标计算机积极拒绝,无法连接。.
2018-03-26 14:50:34 [scrapy.downloadermiddlewares.retry] DEBUG: Retrying > (failed 2 times): Connection was refused by other side: 10061: 由于目标计算机积极拒绝,无法连接。.
2018-03-26 14:50:35 [scrapy.downloadermiddlewares.retry] DEBUG: Gave up retrying er.shtml> (failed 3 times): Connection was refused by other side: 10061: 由于目标计算机积极拒绝,无法连接。.
2018-03-26 14:50:35 [scrapy.core.scraper] ERROR: Error downloading : Con
nection was refused by other side: 10061: 由于目标计算机积极拒绝,无法连接。.
2018-03-26 14:50:35 [scrapy.core.engine] INFO: Closing spider (finished)
2018-03-26 14:50:35 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{'downloader/exception_count': 3,
 'downloader/exception_type_count/twisted.internet.error.ConnectionRefusedError': 3,
 'downloader/request_bytes': 699,
 'downloader/request_count': 3,
 'downloader/request_method_count/GET': 3,
 'finish_reason': 'finished',
 'finish_time': datetime.datetime(2018, 3, 26, 6, 50, 35, 950498),
 'log_count/DEBUG': 4,
 'log_count/ERROR': 1,
 'log_count/INFO': 7,
 'retry/count': 2,
 'retry/max_reached': 1,
 'retry/reason_count/twisted.internet.error.ConnectionRefusedError': 2,
 'scheduler/dequeued': 3,
 'scheduler/dequeued/memory': 3,
 'scheduler/enqueued': 3,
 'scheduler/enqueued/memory': 3,
 'start_time': datetime.datetime(2018, 3, 26, 6, 50, 23, 644724)}

2018-03-26 14:50:35 [scrapy.core.engine] INFO: Spider closed (finished)



爬虫小白新入门开始学Scrapy框架 ,这个我是爬取传智播客的官网信息的案例

但执行程序报出:由于目标计算机积极拒绝,无法连接。

现求大神解决!


源码:

import scrapy
from mySpider.items import MyspiderItem

class itcastSpider(scrapy.Spider):
    #爬虫名称
    name = "itcast"
    #爬取域的范围
    allowed_domains = ["itcast.cn"]
    #爬取的起始页面
    start_urls = ["http://www.itcast.cn/channel/teacher.shtml"]

    def parse(self, response):

        note_list = response.xpath("//div[@class='li_txt']")

        items = []

        for list in note_list:
            #创建一个item字段用来存储解析的数据
             item = MyspiderItem()


            #.extract()是将xpath对象转为Unicode字符串
             te_name = list.xpath("./h3/text()").extract()
            te_title = list.xpath("./h4/text()").extract()
            te_info = list.xpath("./p/text()").extract()

            #xpath打印出来的永远都是个列表所以加[0]索引打印
             # print(te_name[0])
            # print(te_title[0])
            # print(te_info[0])

            #将数据存储于item字段中
             item['te_name'] = te_name[0]
            item['te_title'] = te_title[0]
            item['te_info'] = te_info[0]

            items.append(item)

         return items

你可能感兴趣的:(python,3)