Permalink
Browse files

scrapy crawler

  • Loading branch information...
Matthew Murray Matthew Murray
Matthew Murray authored and Matthew Murray committed May 24, 2017
1 parent 7bb2d08 commit a3d3bfb83d42cc6e6122a54726f9448abc17f92c
No changes.
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# Define here the models for your scraped items
#
# See documentation in:
# http://doc.scrapy.org/en/latest/topics/items.html
import scrapy
class JunoCrawlerItem(scrapy.Item):
artist = scrapy.Field()
title = scrapy.Field()
label = scrapy.Field()
tracks = scrapy.Field()
catalog_number = scrapy.Field()
release_date = scrapy.Field()
genre = scrapy.Field()
@@ -0,0 +1,56 @@
# -*- coding: utf-8 -*-
# Define here the models for your spider middleware
#
# See documentation in:
# http://doc.scrapy.org/en/latest/topics/spider-middleware.html
from scrapy import signals
class JunoCrawlerSpiderMiddleware(object):
# Not all methods need to be defined. If a method is not defined,
# scrapy acts as if the spider middleware does not modify the
# passed objects.
@classmethod
def from_crawler(cls, crawler):
# This method is used by Scrapy to create your spiders.
s = cls()
crawler.signals.connect(s.spider_opened, signal=signals.spider_opened)
return s
def process_spider_input(response, spider):
# Called for each response that goes through the spider
# middleware and into the spider.
# Should return None or raise an exception.
return None
def process_spider_output(response, result, spider):
# Called with the results returned from the Spider, after
# it has processed the response.
# Must return an iterable of Request, dict or Item objects.
for i in result:
yield i
def process_spider_exception(response, exception, spider):
# Called when a spider or process_spider_input() method
# (from other spider middleware) raises an exception.
# Should return either None or an iterable of Response, dict
# or Item objects.
pass
def process_start_requests(start_requests, spider):
# Called with the start requests of the spider, and works
# similarly to the process_spider_output() method, except
# that it doesn’t have a response associated.
# Must return only requests (not items).
for r in start_requests:
yield r
def spider_opened(self, spider):
spider.logger.info('Spider opened: %s' % spider.name)
@@ -0,0 +1,11 @@
# -*- 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
class JunoCrawlerPipeline(object):
def process_item(self, item, spider):
return item
@@ -0,0 +1,90 @@
# -*- coding: utf-8 -*-
# Scrapy settings for juno_crawler project
#
# For simplicity, this file contains only settings considered important or
# commonly used. You can find more settings consulting the documentation:
#
# http://doc.scrapy.org/en/latest/topics/settings.html
# http://scrapy.readthedocs.org/en/latest/topics/downloader-middleware.html
# http://scrapy.readthedocs.org/en/latest/topics/spider-middleware.html
BOT_NAME = 'juno_crawler'
SPIDER_MODULES = ['juno_crawler.spiders']
NEWSPIDER_MODULE = 'juno_crawler.spiders'
# Crawl responsibly by identifying yourself (and your website) on the user-agent
#USER_AGENT = 'juno_crawler (+http://www.yourdomain.com)'
# Obey robots.txt rules
ROBOTSTXT_OBEY = True
# Configure maximum concurrent requests performed by Scrapy (default: 16)
#CONCURRENT_REQUESTS = 32
# Configure a delay for requests for the same website (default: 0)
# See http://scrapy.readthedocs.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
# 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 http://scrapy.readthedocs.org/en/latest/topics/spider-middleware.html
#SPIDER_MIDDLEWARES = {
# 'juno_crawler.middlewares.JunoCrawlerSpiderMiddleware': 543,
#}
# Enable or disable downloader middlewares
# See http://scrapy.readthedocs.org/en/latest/topics/downloader-middleware.html
#DOWNLOADER_MIDDLEWARES = {
# 'juno_crawler.middlewares.MyCustomDownloaderMiddleware': 543,
#}
# Enable or disable extensions
# See http://scrapy.readthedocs.org/en/latest/topics/extensions.html
#EXTENSIONS = {
# 'scrapy.extensions.telnet.TelnetConsole': None,
#}
# Configure item pipelines
# See http://scrapy.readthedocs.org/en/latest/topics/item-pipeline.html
#ITEM_PIPELINES = {
# 'juno_crawler.pipelines.JunoCrawlerPipeline': 300,
#}
# Enable and configure the AutoThrottle extension (disabled by default)
# See http://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 http://scrapy.readthedocs.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'
@@ -0,0 +1,4 @@
# This package will contain the spiders of your Scrapy project
#
# Please refer to the documentation for information on how to create and manage
# your spiders.
@@ -0,0 +1,67 @@
# -*- coding: utf-8 -*-
# import scrapy
from scrapy import Spider
from scrapy.http import Request
from juno_crawler.items import JunoCrawlerItem
class JunoSpider(Spider):
name = "juno"
allowed_domains = ["junodownload.com"]
start_urls = ['http://www.junodownload.com/all/back-cat/releases/?music_product_type=single']
def parse(self, response):
next_page_url = response.xpath('//a[span[contains(@class, "glyphicon-arrow-right")]]/@href').extract_first()
item = JunoCrawlerItem()
releases = response.xpath('.//div[@class="productlist_widget_container"]')
for release in releases:
artist_text = release.xpath(
'.//div[@class="productlist_widget_product_artists"]/span[@class="jq_highlight pwrtext"]/descendant-or-self::*/text()')
artist_list = []
for artist in artist_text:
artist_list.append(artist.extract())
artist = ''.join(artist_list)
item['artist'] = artist
title = release.xpath(
'.//div[@class="productlist_widget_product_title"]/span[@class="jq_highlight pwrtext"]/a/text()').extract_first()
item['title'] = title
label = release.xpath(
'.//div[@class="productlist_widget_product_label"]/span[@class="jq_highlight pwrtext"]/a/text()').extract_first()
item['label'] = label
track_div = release.xpath('.//div[@class="productlist_widget_tracklist_left"]')
for tracks in track_div:
track_urls = tracks.xpath(
'.//div[@class="productlist_widget_tracklist_row"]/a[@ua_action="play"]/@href').extract()
track_name_list = tracks.xpath(
'.//div[@class="productlist_widget_tracklist_row_text"]/span[@class="jq_highlight"]/text()').extract()
track_names = []
for tracks in track_name_list:
track = tracks.replace('\t','')
if len(track) >0:
track_names.append(track)
tracks = list(zip(track_names, track_urls))
item['tracks'] = tracks
catalog_number = release.xpath(
'.//div[@class="productlist_widget_product_preview_buy"]/text()').extract_first()
catalog_number = catalog_number.strip()
item['catalog_number'] = catalog_number
release_date = release.xpath(
'.//div[@class="productlist_widget_product_preview_buy"]/span/text()').extract_first()
item['release_date'] = release_date
genre = release.xpath(
'.//div[@class="productlist_widget_product_preview_buy"]/span/following-sibling::span/text()').extract_first()
genre = genre.strip()
item['genre'] = genre
yield item
yield Request(next_page_url)
View
No changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# Define here the models for your scraped items
#
# See documentation in:
# http://doc.scrapy.org/en/latest/topics/items.html
import scrapy
class JunoCrawlerItem(scrapy.Item):
artist = scrapy.Field()
title = scrapy.Field()
label = scrapy.Field()
tracks = scrapy.Field()
catalog_number = scrapy.Field()
release_date = scrapy.Field()
genre = scrapy.Field()
@@ -0,0 +1,56 @@
# -*- coding: utf-8 -*-
# Define here the models for your spider middleware
#
# See documentation in:
# http://doc.scrapy.org/en/latest/topics/spider-middleware.html
from scrapy import signals
class JunoCrawlerSpiderMiddleware(object):
# Not all methods need to be defined. If a method is not defined,
# scrapy acts as if the spider middleware does not modify the
# passed objects.
@classmethod
def from_crawler(cls, crawler):
# This method is used by Scrapy to create your spiders.
s = cls()
crawler.signals.connect(s.spider_opened, signal=signals.spider_opened)
return s
def process_spider_input(response, spider):
# Called for each response that goes through the spider
# middleware and into the spider.
# Should return None or raise an exception.
return None
def process_spider_output(response, result, spider):
# Called with the results returned from the Spider, after
# it has processed the response.
# Must return an iterable of Request, dict or Item objects.
for i in result:
yield i
def process_spider_exception(response, exception, spider):
# Called when a spider or process_spider_input() method
# (from other spider middleware) raises an exception.
# Should return either None or an iterable of Response, dict
# or Item objects.
pass
def process_start_requests(start_requests, spider):
# Called with the start requests of the spider, and works
# similarly to the process_spider_output() method, except
# that it doesn’t have a response associated.
# Must return only requests (not items).
for r in start_requests:
yield r
def spider_opened(self, spider):
spider.logger.info('Spider opened: %s' % spider.name)
View
@@ -0,0 +1,11 @@
# -*- 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
class JunoCrawlerPipeline(object):
def process_item(self, item, spider):
return item
Oops, something went wrong.

0 comments on commit a3d3bfb

Please sign in to comment.