Skip to content

Commit

Permalink
crawler complete
Browse files Browse the repository at this point in the history
  • Loading branch information
JerinFrancisA committed Sep 2, 2019
0 parents commit e14bc46
Show file tree
Hide file tree
Showing 17 changed files with 655 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/Bikes.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file added Bikes/__init__.py
Empty file.
9 changes: 9 additions & 0 deletions Bikes/items.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import scrapy


class BikesItem(scrapy.Item):

item_name = scrapy.Field()
item_url = scrapy.Field()
item_price = scrapy.Field()

103 changes: 103 additions & 0 deletions Bikes/middlewares.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# -*- coding: utf-8 -*-

# Define here the models for your spider middleware
#
# See documentation in:
# https://doc.scrapy.org/en/latest/topics/spider-middleware.html

from scrapy import signals


class BikesSpiderMiddleware(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(self, 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(self, 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(self, 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(self, 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)


class BikesDownloaderMiddleware(object):
# Not all methods need to be defined. If a method is not defined,
# scrapy acts as if the downloader 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_request(self, request, spider):
# Called for each request that goes through the downloader
# middleware.

# Must either:
# - return None: continue processing this request
# - or return a Response object
# - or return a Request object
# - or raise IgnoreRequest: process_exception() methods of
# installed downloader middleware will be called
return None

def process_response(self, request, response, spider):
# Called with the response returned from the downloader.

# Must either;
# - return a Response object
# - return a Request object
# - or raise IgnoreRequest
return response

def process_exception(self, request, exception, spider):
# Called when a download handler or a process_request()
# (from other downloader middleware) raises an exception.

# Must either:
# - return None: continue processing this exception
# - return a Response object: stops process_exception() chain
# - return a Request object: stops process_exception() chain
pass

def spider_opened(self, spider):
spider.logger.info('Spider opened: %s' % spider.name)
11 changes: 11 additions & 0 deletions Bikes/pipelines.py
Original file line number Diff line number Diff line change
@@ -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: https://doc.scrapy.org/en/latest/topics/item-pipeline.html


class BikesPipeline(object):
def process_item(self, item, spider):
return item
90 changes: 90 additions & 0 deletions Bikes/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# -*- coding: utf-8 -*-

# Scrapy settings for Bikes 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 = 'Bikes'

SPIDER_MODULES = ['Bikes.spiders']
NEWSPIDER_MODULE = 'Bikes.spiders'


# Crawl responsibly by identifying yourself (and your website) on the user-agent
#USER_AGENT = 'Bikes (+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 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

# 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 = {
# 'Bikes.middlewares.BikesSpiderMiddleware': 543,
#}

# Enable or disable downloader middlewares
# See https://doc.scrapy.org/en/latest/topics/downloader-middleware.html
#DOWNLOADER_MIDDLEWARES = {
# 'Bikes.middlewares.BikesDownloaderMiddleware': 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 = {
# 'Bikes.pipelines.BikesPipeline': 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'
4 changes: 4 additions & 0 deletions Bikes/spiders/__init__.py
Original file line number Diff line number Diff line change
@@ -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.
34 changes: 34 additions & 0 deletions Bikes/spiders/bikeallspy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
import scrapy
from ..items import BikesItem


class BikeallspySpider(scrapy.Spider):
name = 'bikeallspy'
start_urls = [
'https://www.amazon.in/s?i=automotive&bbn=5258392031&rh=n%3A4772060031%2Cn%3A%214772061031%2Cn%3A5257478031%2Cn%3A5258045031%2Cn%3A5258392031%2Cp_85%3A10440599031&pf_rd_i=5258045031&pf_rd_m=A1K21FY43GMZF8&pf_rd_p=0da2298e-ae9e-4b16-8e83-6a3410e62dfd&pf_rd_r=SPESDE2T7MZ4VMQYAPGN&pf_rd_s=merchandised-search-3&pf_rd_t=101&ref=s9_acss_bw_cg_Heltype_3d1_w',
'https://www.amazon.in/s?i=automotive&bbn=5258390031&rh=n%3A4772060031%2Cn%3A%214772061031%2Cn%3A5257478031%2Cn%3A5258045031%2Cn%3A5258390031%2Cp_85%3A10440599031&pf_rd_i=5258045031&pf_rd_m=A1K21FY43GMZF8&pf_rd_p=0da2298e-ae9e-4b16-8e83-6a3410e62dfd&pf_rd_r=FAEFY617NZX98JQB1XA5&pf_rd_s=merchandised-search-3&pf_rd_t=101&ref=s9_acss_bw_cg_Heltype_3a1_w',
'https://www.amazon.in/s?i=automotive&bbn=5258042031&rh=n%3A4772060031%2Cn%3A%214772061031%2Cn%3A5257478031%2Cn%3A5257575031%2Cn%3A5258042031%2Cp_85%3A10440599031&pf_rd_i=5257478031&pf_rd_m=A1K21FY43GMZF8&pf_rd_p=bd3ba4d6-2c95-4851-9fe1-3d1d7cf71d74&pf_rd_r=75DJC694E9VZZMKAZDAN&pf_rd_s=merchandised-search-8&pf_rd_t=101&ref=s9_acss_bw_cg_BKSafety_4a1_w',
'https://www.amazon.in/s?i=automotive&bbn=5258050031&rh=n%3A4772060031%2Cn%3A%214772061031%2Cn%3A5257478031%2Cn%3A5257575031%2Cn%3A5258050031%2Cp_85%3A10440599031&s=price-desc-rank&pf_rd_i=5257478031&pf_rd_m=A1K21FY43GMZF8&pf_rd_p=bd3ba4d6-2c95-4851-9fe1-3d1d7cf71d74&pf_rd_r=GWY7511V5XQF6H84MHG8&pf_rd_s=merchandised-search-8&pf_rd_t=101&ref=s9_acss_bw_cg_BKSafety_4b1_w',
'https://www.amazon.in/s?k=biker+face+mask&i=automotive&rh=n%3A4772060031%2Cp_6%3AAT95IG9ONZD7S%2Cp_85%3A10440599031&pf_rd_i=5257478031&pf_rd_m=A1K21FY43GMZF8&pf_rd_p=bd3ba4d6-2c95-4851-9fe1-3d1d7cf71d74&pf_rd_r=E9EX8YR968BFB2SX6Y8J&pf_rd_s=merchandised-search-8&pf_rd_t=101&ref=s9_acss_bw_cg_BKSafety_4c1_w',
'https://www.amazon.in/s?k=crash+guard+for+bike&rh=p_85%3A10440599031&pf_rd_i=5257478031&pf_rd_m=A1K21FY43GMZF8&pf_rd_p=bd3ba4d6-2c95-4851-9fe1-3d1d7cf71d74&pf_rd_r=FKRZGAMK7SZRP0X117K1&pf_rd_s=merchandised-search-8&pf_rd_t=101&ref=s9_acss_bw_cg_BKSafety_5a1_w',
'https://www.amazon.in/s?k=engine+oil+for+bike&pf_rd_i=5257478031&pf_rd_m=A1K21FY43GMZF8&pf_rd_p=eca27583-bc82-4947-9754-656d407adfd0&pf_rd_r=XTNQTEXNTY139QMM8RH5&pf_rd_s=merchandised-search-10&pf_rd_t=101&ref=s9_acss_bw_cg_BKPR_3a1_w',
'https://www.amazon.in/s?i=automotive&bbn=5257570031&rh=n%3A4772060031%2Cn%3A%214772061031%2Cn%3A5257478031%2Cn%3A5257570031%2Cp_85%3A10440599031&pf_rd_i=5257478031&pf_rd_m=A1K21FY43GMZF8&pf_rd_p=eca27583-bc82-4947-9754-656d407adfd0&pf_rd_r=SW51S5AKQEN25HA18K3S&pf_rd_s=merchandised-search-10&pf_rd_t=101&ref=s9_acss_bw_cg_BKPR_3b1_w',
'https://www.amazon.in/s?k=rims+and+alloy+wheels+for+bike&i=automotive&rh=n%3A4772060031%2Cn%3A5257478031%2Cn%3A5257578031%2Cp_85%3A10440599031&pf_rd_i=5257478031&pf_rd_m=A1K21FY43GMZF8&pf_rd_p=eca27583-bc82-4947-9754-656d407adfd0&pf_rd_r=K232EBDMKR425YX4SGX6&pf_rd_s=merchandised-search-10&pf_rd_t=101&ref=s9_acss_bw_cg_BKPR_4d1_w',
'https://www.amazon.in/s?i=automotive&bbn=5257919031&rh=n%3A4772060031%2Cn%3A%214772061031%2Cn%3A5257478031%2Cn%3A5257561031%2Cn%3A5257919031%2Cp_85%3A10440599031&pf_rd_i=5257478031&pf_rd_m=A1K21FY43GMZF8&pf_rd_p=0588bcc2-91b8-4087-82a1-8c04de919b60&pf_rd_r=6A3CA12X74KA5W4RA41G&pf_rd_s=merchandised-search-12&pf_rd_t=101&ref=s9_acss_bw_cg_BKAcc_3a1_w',
'https://www.amazon.in/s?k=mobile+holder+for+bike+%7C+mobile+bike+charger&i=automotive&bbn=4772060031&rh=n%3A4772060031%2Cp_6%3AAT95IG9ONZD7S&pf_rd_i=5257478031&pf_rd_m=A1K21FY43GMZF8&pf_rd_p=0588bcc2-91b8-4087-82a1-8c04de919b60&pf_rd_r=JBZ9ZAY4SK4W682YTAZW&pf_rd_s=merchandised-search-12&pf_rd_t=101&ref=s9_acss_bw_cg_BKAcc_3b1_w',
]

def parse(self, response):
items = BikesItem()
all_items = response.css('.s-include-content-margin')
for item in all_items:
item_name = item.css('.a-color-base.a-text-normal').css('::text').extract_first()
item_url = item.css('.s-image-square-aspect .s-image').css('::attr(src)').extract_first()
item_price = item.css('.a-price-whole').css('::text').extract_first()

items['item_name'] = item_name
items['item_url'] = item_url
items['item_price'] = item_price

yield items
28 changes: 28 additions & 0 deletions Bikes/spiders/bikehelmetspy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
import scrapy
from ..items import BikesItem


class BikespySpider(scrapy.Spider):
name = 'bikehelmetspy'
start_urls = [
'https://www.amazon.in/s?i=automotive&bbn=5258392031&rh=n%3A4772060031%2Cn%3A%214772061031%2Cn%3A5257478031%2Cn%3A5258045031%2Cn%3A5258392031%2Cp_85%3A10440599031&pf_rd_i=5258045031&pf_rd_m=A1K21FY43GMZF8&pf_rd_p=0da2298e-ae9e-4b16-8e83-6a3410e62dfd&pf_rd_r=SPESDE2T7MZ4VMQYAPGN&pf_rd_s=merchandised-search-3&pf_rd_t=101&ref=s9_acss_bw_cg_Heltype_3d1_w',
'https://www.amazon.in/s?i=automotive&bbn=5258392031&rh=n%3A4772060031%2Cn%3A4772061031%2Cn%3A5257478031%2Cn%3A5258045031%2Cn%3A5258392031%2Cp_85%3A10440599031&page=2&pf_rd_i=5258045031&pf_rd_m=A1K21FY43GMZF8&pf_rd_p=0da2298e-ae9e-4b16-8e83-6a3410e62dfd&pf_rd_r=SPESDE2T7MZ4VMQYAPGN&pf_rd_s=merchandised-search-3&pf_rd_t=101&qid=1567426649&ref=sr_pg_2',
'https://www.amazon.in/s?i=automotive&bbn=5258390031&rh=n%3A4772060031%2Cn%3A%214772061031%2Cn%3A5257478031%2Cn%3A5258045031%2Cn%3A5258390031%2Cp_85%3A10440599031&pf_rd_i=5258045031&pf_rd_m=A1K21FY43GMZF8&pf_rd_p=0da2298e-ae9e-4b16-8e83-6a3410e62dfd&pf_rd_r=FAEFY617NZX98JQB1XA5&pf_rd_s=merchandised-search-3&pf_rd_t=101&ref=s9_acss_bw_cg_Heltype_3a1_w',
'',
]

def parse(self, response):
items = BikesItem()
all_items = response.css('.s-include-content-margin')
for item in all_items:
item_name = item.css('.a-color-base.a-text-normal').css('::text').extract_first()
item_url = item.css('.s-image-square-aspect .s-image').css('::attr(src)').extract_first()
item_price = item.css('.a-price-whole').css('::text').extract_first()

items['item_name'] = item_name
items['item_url'] = item_url
items['item_price'] = item_price

yield items

Loading

0 comments on commit e14bc46

Please sign in to comment.