這篇文章主要介紹了Scrapy框架基本命令有哪些,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
創(chuàng)新互聯建站服務項目包括永修網站建設、永修網站制作、永修網頁制作以及永修網絡營銷策劃等。多年來,我們專注于互聯網行業(yè),利用自身積累的技術優(yōu)勢、行業(yè)經驗、深度合作伙伴關系等,向廣大中小型企業(yè)、政府機構等提供互聯網行業(yè)的解決方案,永修網站推廣取得了明顯的社會效益與經濟效益。目前,我們服務的客戶以成都為中心已經輻射到永修省份的部分城市,未來相信會繼續(xù)擴大服務區(qū)域并繼續(xù)獲得客戶的支持與信任!Scrapy框架基本命令1.創(chuàng)建爬蟲項目
scrapy startproject [項目名稱]
2.創(chuàng)建爬蟲文件
scrapy genspider +文件名+網址
3.運行(crawl)
scrapy crawl 爬蟲名稱 # -o output 輸出數據到文件 scrapy crawl [爬蟲名稱] -o zufang.json scrapy crawl [爬蟲名稱] -o zufang.csv
4.check檢查錯誤
scrapy check
5.list返回項目所有spider
scrapy list
6.view 存儲、打開網頁
scrapy view http://www.baidu.com
7.scrapy shell, 進入終端
scrapy shell https://www.baidu.com
8.scrapy runspider
scrapy runspider zufang_spider.pyScrapy框架: settings.py設置
# -*- coding: utf-8 -*- # Scrapy settings for maitian project # # For simplicity, this file contains only settings considered important or # commonly used. You can find more settings consulting the documentation: # # https://doc.scrapy.org/en/latest/topics/settings.html # https://doc.scrapy.org/en/latest/topics/downloader-middleware.html # https://doc.scrapy.org/en/latest/topics/spider-middleware.html BOT_NAME = 'maitian' SPIDER_MODULES = ['maitian.spiders'] NEWSPIDER_MODULE = 'maitian.spiders' #不能批量設置 # Crawl responsibly by identifying yourself (and your website) on the user-agent USER_AGENT = 'maitian (+http://www.yourdomain.com)' #默認遵守robots協議 # Obey robots.txt rules ROBOTSTXT_OBEY = False #設置日志文件 LOG_FILE="maitian.log" #日志等級分為5種:1.DEBUG 2.INFO 3.Warning 4.ERROR 5.CRITICAL #等級越高 輸出的日志越少 # LOG_LEVEL="INFO" #scrapy設置大并發(fā)數 默認16 # Configure maximum concurrent requests performed by Scrapy (default: 16) #CONCURRENT_REQUESTS = 32 #設置批量延遲請求16 等待3秒再發(fā)16 秒 # Configure a delay for requests for the same website (default: 0) # See https://doc.scrapy.org/en/latest/topics/settings.html#download-delay # See also autothrottle settings and docs #DOWNLOAD_DELAY = 3 # The download delay setting will honor only one of: #CONCURRENT_REQUESTS_PER_DOMAIN = 16 #CONCURRENT_REQUESTS_PER_IP = 16 #cookie 不生效 默認是True # Disable cookies (enabled by default) #COOKIES_ENABLED = False #遠程 # Disable Telnet Console (enabled by default) #TELNETCONSOLE_ENABLED = False #加載默認的請求頭 # Override the default request headers: #DEFAULT_REQUEST_HEADERS = { # 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', # 'Accept-Language': 'en', #} #爬蟲中間件 # Enable or disable spider middlewares # See https://doc.scrapy.org/en/latest/topics/spider-middleware.html #SPIDER_MIDDLEWARES = { # 'maitian.middlewares.MaitianSpiderMiddleware': 543, #} #下載中間件 # Enable or disable downloader middlewares # See https://doc.scrapy.org/en/latest/topics/downloader-middleware.html #DOWNLOADER_MIDDLEWARES = { # 'maitian.middlewares.MaitianDownloaderMiddleware': 543, #} # Enable or disable extensions # See https://doc.scrapy.org/en/latest/topics/extensions.html #EXTENSIONS = { # 'scrapy.extensions.telnet.TelnetConsole': None, #} #在配置文件 開啟管道 #優(yōu)先級的范圍 0--1000;值越小 優(yōu)先級越高 # Configure item pipelines # See https://doc.scrapy.org/en/latest/topics/item-pipeline.html #ITEM_PIPELINES = { # 'maitian.pipelines.MaitianPipeline': 300, #} # Enable and configure the AutoThrottle extension (disabled by default) # See https://doc.scrapy.org/en/latest/topics/autothrottle.html #AUTOTHROTTLE_ENABLED = True # The initial download delay #AUTOTHROTTLE_START_DELAY = 5 # The maximum download delay to be set in case of high latencies #AUTOTHROTTLE_MAX_DELAY = 60 # The average number of requests Scrapy should be sending in parallel to # each remote server #AUTOTHROTTLE_TARGET_CONCURRENCY = 1.0 # Enable showing throttling stats for every response received: #AUTOTHROTTLE_DEBUG = False # Enable and configure HTTP caching (disabled by default) # See https://doc.scrapy.org/en/latest/topics/downloader-middleware.html#httpcache-middleware-settings #HTTPCACHE_ENABLED = True #HTTPCACHE_EXPIRATION_SECS = 0 #HTTPCACHE_DIR = 'httpcache' #HTTPCACHE_IGNORE_HTTP_CODES = [] #HTTPCACHE_STORAGE = 'scrapy.extensions.httpcache.FilesystemCacheStorage'
感謝你能夠認真閱讀完這篇文章,希望小編分享的“Scrapy框架基本命令有哪些”這篇文章對大家有幫助,同時也希望大家多多支持創(chuàng)新互聯,關注創(chuàng)新互聯行業(yè)資訊頻道,更多相關知識等著你來學習!
網頁名稱:Scrapy框架基本命令有哪些-創(chuàng)新互聯
當前網址:http://muchs.cn/article24/ceeije.html
成都網站建設公司_創(chuàng)新互聯,為您提供網頁設計公司、企業(yè)建站、商城網站、標簽優(yōu)化、網站維護、網站導航
聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯