当前位置: 首页 > news >正文

免费扑克网站代码/新开传奇网站

免费扑克网站代码,新开传奇网站,农业生态园电商网站建设,wordpress发文器版权声明:本文可能为博主原创文章,若标明出处可随便转载。 https://blog.csdn.net/Jailman/article/details/79170849 这是一个使用scrapy的ImagesPipeline爬取下载图片的示例,生成的图片保存在爬虫的full文件夹里。 scrapy startproject Dou…
版权声明:本文可能为博主原创文章,若标明出处可随便转载。 https://blog.csdn.net/Jailman/article/details/79170849

这是一个使用scrapy的ImagesPipeline爬取下载图片的示例,生成的图片保存在爬虫的full文件夹里。

scrapy startproject DoubanImgs

cd DoubanImgs

scrapy genspider download_douban  douban.com

vim spiders/download_douban.py

# coding=utf-8
from scrapy.spiders import Spider
import re
from scrapy import Request
from ..items import DoubanImgsItemclass download_douban(Spider):name = 'download_douban'default_headers = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8','Accept-Encoding': 'gzip, deflate, sdch, br','Accept-Language': 'zh-CN,zh;q=0.8,en;q=0.6','Cache-Control': 'max-age=0','Connection': 'keep-alive','Host': 'www.douban.com','User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36',}def __init__(self, url='1638835355', *args, **kwargs):self.allowed_domains = ['douban.com']self.start_urls = []for i in xrange(23):if i == 0:page_url = 'http://www.douban.com/photos/album/' + urlelse:page_url = 'http://www.douban.com/photos/album/' + url + '/?start=' + str(i*18)self.start_urls.append(page_url)self.url = url# call the father base function# super(download_douban, self).__init__(*args, **kwargs)def start_requests(self):for url in self.start_urls:yield Request(url=url, headers=self.default_headers, callback=self.parse)def parse(self, response):list_imgs = response.xpath('//div[@class="photolst clearfix"]//img/@src').extract()if list_imgs:item = DoubanImgsItem()item['image_urls'] = list_imgsyield item


vim settings.py

# -*- coding: utf-8 -*-# Scrapy settings for DoubanImgs 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.htmlBOT_NAME = 'DoubanImgs'SPIDER_MODULES = ['DoubanImgs.spiders']
NEWSPIDER_MODULE = 'DoubanImgs.spiders'ITEM_PIPELINES = {'DoubanImgs.pipelines.DoubanImgDownloadPipeline': 300,
}
IMAGES_STORE = '.'
IMAGES_EXPIRES = 90# Crawl responsibly by identifying yourself (and your website) on the user-agent
#USER_AGENT = 'DoubanImgs (+http://www.yourdomain.com)'# Obey robots.txt rules
ROBOTSTXT_OBEY = False# Configure maximum concurrent requests performed by Scrapy (default: 16)
#CONCURRENT_REQUESTS = 32# 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 = 0.5
# The download delay setting will honor only one of:
#CONCURRENT_REQUESTS_PER_DOMAIN = 16
#CONCURRENT_REQUESTS_PER_IP = 16# 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 = {
#    'DoubanImgs.middlewares.DoubanimgsSpiderMiddleware': 543,
#}# Enable or disable downloader middlewares
# See https://doc.scrapy.org/en/latest/topics/downloader-middleware.html
#DOWNLOADER_MIDDLEWARES = {
#    'DoubanImgs.middlewares.DoubanimgsDownloaderMiddleware': 543,
#}# Enable or disable extensions
# See https://doc.scrapy.org/en/latest/topics/extensions.html
#EXTENSIONS = {
#    'scrapy.extensions.telnet.TelnetConsole': None,
#}# Configure item pipelines
# See https://doc.scrapy.org/en/latest/topics/item-pipeline.html
#ITEM_PIPELINES = {
#    'DoubanImgs.pipelines.DoubanimgsPipeline': 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'

vim items.py

# -*- coding: utf-8 -*-# Define here the models for your scraped items
#
# See documentation in:
# https://doc.scrapy.org/en/latest/topics/items.html
import scrapy
from scrapy import Fieldclass DoubanImgsItem(scrapy.Item):# define the fields for your item here like:# name = scrapy.Field()image_urls = Field()images = Field()image_paths = Field()



vim pipelines.py

# -*- coding: utf-8 -*-# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html
from scrapy.pipelines.images import ImagesPipeline
from scrapy.exceptions import DropItem
from scrapy import Request
from scrapy import logclass DoubanImgsPipeline(object):def process_item(self, item, spider):return itemclass DoubanImgDownloadPipeline(ImagesPipeline):default_headers = {'accept': 'image/webp,image/*,*/*;q=0.8','accept-encoding': 'gzip, deflate, sdch, br','accept-language': 'zh-CN,zh;q=0.8,en;q=0.6','cookie': 'bid=yQdC/AzTaCw','referer': 'https://www.douban.com/photos/photo/2370443040/','user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36',}def get_media_requests(self, item, info):for image_url in item['image_urls']:self.default_headers['referer'] = image_urlyield Request(image_url, headers=self.default_headers)def item_completed(self, results, item, info):image_paths = [x['path'] for ok, x in results if ok]if not image_paths:raise DropItem("Item contains no images")item['image_paths'] = image_pathsreturn item




http://www.lbrq.cn/news/769771.html

相关文章:

  • 青岛网站制作价格/怎样建立一个网站
  • 手表网站背景素材/青岛做网站的公司哪家好
  • 云霄县建设局网站投诉/2022年最新新闻播报稿件
  • wordpress数据库损坏网站/武汉刚刚发生的新闻
  • wordpress 商城模版/网站关键词优化排名技巧
  • 建设网站前端/seo外链
  • 如何评判一个网站建设的怎么样/百度百度一下就知道
  • 阿里巴巴做国际网站要多少钱/灰色词seo推广
  • 政府单位建设网站的申请报告/外贸企业网站制作哪家好
  • 上海网站建设 上海网站制作/深圳营销推广公司
  • 深圳开发网站建设/怎样加入网络营销公司
  • 黄骅招聘信息最新/seo免费教程
  • 怎么发布自己做的网站/网站注册时间查询
  • 怎么用h5做网站/seo网站排名优化快速排
  • 利津网站定制/推广营销平台
  • 人大网站建设情况介绍/手机金融界网站
  • 璧山集团网站建设/com网站域名注册
  • 网站链接维护怎么做/苏州网站维护
  • 装饰公司东莞网站建设/seo排名优化教学
  • 网站论坛源码/目前主流搜索引擎是哪种
  • 做网站和做网页/模板之家
  • 免费做国际网站有哪些/b站视频推广网站动漫
  • wordpress地址和站点地址有什么用/网站推广多少钱
  • 专业集团门户网站建设/搜索引擎优化的方法包括
  • 泉州优化seo网站关键词优化/网站备案查询工信部官网
  • wordpress修改css样式的方法/广州seo黑帽培训
  • 单位网站建设费如何入账/网络营销公司经营范围
  • 毕业设计 做网站/武汉好的seo优化网
  • 广告设计图片大全模板/百度的关键词优化
  • 如何做高校的网站版面设计/体验营销
  • Android平台RTSP播放器选型指南:从开源方案到跨平台低延迟专业SDK
  • RabbitMQ:Windows版本安装部署
  • 【C语言强化训练16天】--从基础到进阶的蜕变之旅:Day3
  • Seed-VC:零样本语音转换与扩散transformer
  • OBOO鸥柏丨智能会议平板教学查询一体机交互式触摸终端招标投标核心标底参数要求
  • CTO如何通过录音转写和音频降噪,提升企业远程协作效率?