最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Scrapy框架基本命令與settings.py設置

 更新時間:2020年02月06日 08:48:38   作者:hankleo  
這篇文章主要介紹了Scrapy框架基本命令與settings.py設置,結合實例形式分析了創(chuàng)建爬蟲項目、創(chuàng)建爬蟲文件、存儲、打開網(wǎng)頁及settings.py設置等相關操作技巧,需要的朋友可以參考下

本文實例講述了Scrapy框架基本命令與settings.py設置。分享給大家供大家參考,具體如下:

Scrapy框架基本命令

1.創(chuàng)建爬蟲項目

scrapy startproject [項目名稱]

2.創(chuàng)建爬蟲文件

scrapy genspider +文件名+網(wǎng)址

3.運行(crawl)

scrapy crawl 爬蟲名稱
# -o output 輸出數(shù)據(jù)到文件
scrapy crawl [爬蟲名稱] -o zufang.json
scrapy crawl [爬蟲名稱] -o zufang.csv

4.check檢查錯誤

scrapy check

5.list返回項目所有spider

scrapy list

6.view 存儲、打開網(wǎng)頁

scrapy view http://www.baidu.com

7.scrapy shell, 進入終端

scrapy shell https://www.baidu.com

8.scrapy runspider

scrapy runspider zufang_spider.py

Scrapy框架: 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協(xié)議
# 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ā)數(shù) 默認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'

更多相關內容可查看本站專題:《Python Socket編程技巧總結》、《Python正則表達式用法總結》、《Python數(shù)據(jù)結構與算法教程》、《Python函數(shù)使用技巧總結》、《Python字符串操作技巧匯總》、《Python入門與進階經(jīng)典教程》及《Python文件與目錄操作技巧匯總

希望本文所述對大家基于Scrapy框架的Python程序設計有所幫助。

相關文章

最新評論

阳山县| 上思县| 苏尼特右旗| 大新县| 金华市| 大邑县| 威远县| 安陆市| 加查县| 西吉县| 香河县| 南京市| 福州市| 昭平县| 会理县| 黄大仙区| 措美县| 荆州市| 海林市| 鸡泽县| 翁牛特旗| 钦州市| 肃宁县| 伊通| 商丘市| 郓城县| 福安市| 兴国县| 饶阳县| 吐鲁番市| 都匀市| 邢台市| 韶山市| 克山县| 怀来县| 原阳县| 牙克石市| 辉县市| 独山县| 通化县| 安仁县|