diff --git a/AmazonChecker/__init__.py b/AmazonChecker/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/AmazonChecker/items.py b/AmazonChecker/items.py new file mode 100644 index 0000000..3510a35 --- /dev/null +++ b/AmazonChecker/items.py @@ -0,0 +1,14 @@ +# -*- 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 + + +class Amazon-checkerItem(scrapy.Item): + # define the fields for your item here like: + # name = scrapy.Field() + pass diff --git a/AmazonChecker/middlewares.py b/AmazonChecker/middlewares.py new file mode 100644 index 0000000..6d70318 --- /dev/null +++ b/AmazonChecker/middlewares.py @@ -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 Amazon-checkerSpiderMiddleware(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 Amazon-checkerDownloaderMiddleware(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) diff --git a/AmazonChecker/pipelines.py b/AmazonChecker/pipelines.py new file mode 100644 index 0000000..b0525e3 --- /dev/null +++ b/AmazonChecker/pipelines.py @@ -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 AmazonCheckerPipeline(object): + def process_item(self, item, spider): + return item diff --git a/AmazonChecker/settings.py b/AmazonChecker/settings.py new file mode 100644 index 0000000..dd68b28 --- /dev/null +++ b/AmazonChecker/settings.py @@ -0,0 +1,90 @@ +# -*- coding: utf-8 -*- + +# Scrapy settings for AmazonChecker 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 = 'AmazonChecker' + +SPIDER_MODULES = ['AmazonChecker.spiders'] +NEWSPIDER_MODULE = 'AmazonChecker.spiders' + + +# Crawl responsibly by identifying yourself (and your website) on the user-agent +USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36' + +# 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 = 3 +# The download delay setting will honor only one of: +#CONCURRENT_REQUESTS_PER_DOMAIN = 16 +#CONCURRENT_REQUESTS_PER_IP = 16 + +# Disable coAmazonCheckeries (enabled by default) +#COAMAZON-CHECKERIES_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 = { +# 'AmazonChecker.middlewares.Amazon-checkerSpiderMiddleware': 543, +#} + +# Enable or disable downloader middlewares +# See https://doc.scrapy.org/en/latest/topics/downloader-middleware.html +#DOWNLOADER_MIDDLEWARES = { +# 'AmazonChecker.middlewares.Amazon-checkerDownloaderMiddleware': 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 = { +# 'AmazonChecker.pipelines.Amazon-checkerPipeline': 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' diff --git a/AmazonChecker/spiders/AmazonChecker.py b/AmazonChecker/spiders/AmazonChecker.py new file mode 100644 index 0000000..d45be87 --- /dev/null +++ b/AmazonChecker/spiders/AmazonChecker.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +import scrapy + + +class AmazonChecker(scrapy.Spider): + name = 'AmazonChecker' + allowed_domains = ['amazon.fr'] + start_urls = ['https://www.amazon.fr/ap/signin?_encoding=UTF8&ignoreAuthState=1&openid.assoc_handle=frflex&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0&openid.pape.max_auth_age=0&openid.return_to=https%3A%2F%2Fwww.amazon.fr%2F%3Fref_%3Dnav_custrec_signin&switch_account='] + + def parse(self, response): + if not self.username or not self.password: + print ('pas bon') + else: + return scrapy.FormRequest.from_response( + response, + formdata={'username': self.username, 'password': self.password}, + callback=self.after_login + ) + + def after_login(self, response): + print (response.body) diff --git a/AmazonChecker/spiders/__init__.py b/AmazonChecker/spiders/__init__.py new file mode 100644 index 0000000..ebd689a --- /dev/null +++ b/AmazonChecker/spiders/__init__.py @@ -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. diff --git a/README.md b/README.md index e46805b..81390bf 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Amazon Checker -[![Build Status](https://scrutinizer-ci.com/g/kangoo13/amazon-checker/badges/build.png?b=master)](https://scrutinizer-ci.com/g/kangoo13/amazon-checker/build-status/master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/kangoo13/amazon-checker/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/kangoo13/amazon-checker/?branch=master) [![CircleCI](https://circleci.com/gh/kangoo13/amazon-checker/tree/master.svg?style=svg)](https://circleci.com/gh/kangoo13/amazon-checker/tree/master) [![Code Climate](https://codeclimate.com/github/kangoo13/amazon-checker/badges/gpa.svg)](https://codeclimate.com/github/kangoo13/amazon-checker) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/aa2adb7aac514da497b154d6ad37db3c)](https://www.codacy.com/app/kangoo13/amazon-checker) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat)](http://makeapullrequest.com) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) +[![Build Status](https://scrutinizer-ci.com/g/kangoo13/AmazonChecker/badges/build.png?b=master)](https://scrutinizer-ci.com/g/kangoo13/AmazonChecker/build-status/master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/kangoo13/AmazonChecker/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/kangoo13/AmazonChecker/?branch=master) [![CircleCI](https://circleci.com/gh/kangoo13/AmazonChecker/tree/master.svg?style=svg)](https://circleci.com/gh/kangoo13/AmazonChecker/tree/master) [![Code Climate](https://codeclimate.com/github/kangoo13/AmazonChecker/badges/gpa.svg)](https://codeclimate.com/github/kangoo13/AmazonChecker) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/aa2adb7aac514da497b154d6ad37db3c)](https://www.codacy.com/app/kangoo13/AmazonChecker) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat)](http://makeapullrequest.com) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) -Work In Progress. \ No newline at end of file +Work In Progress. diff --git a/scrapy.cfg b/scrapy.cfg new file mode 100644 index 0000000..4391ed3 --- /dev/null +++ b/scrapy.cfg @@ -0,0 +1,11 @@ +# Automatically created by: scrapy startproject +# +# For more information about the [deploy] section see: +# https://scrapyd.readthedocs.io/en/latest/deploy.html + +[settings] +default = AmazonChecker.settings + +[deploy] +#url = http://localhost:6800/ +project = AmazonChecker