Commit 4419f630 authored by Kyryll Parolis's avatar Kyryll Parolis
Browse files

Merge branch 'release/0.0.1'

parents 7dc873f0 ece77f6d
# -*- coding: utf-8 -*-
from database.connection import db
from database.models import ContractorData
from scrapy.exceptions import DropItem
from sqlalchemy.exc import IntegrityError
class BusinessPipeline:
def process_item(self, item, spider):
# record = ContractorData(name=item['name'],
# # contractor_id=item['contractor_id'],
# category=item['category'],
# rate=item['rate'],
# rate_category=item['rate_category'],
# phone=item['phone'],
# email=item['email'],
# website=item['website'],
# is_licensed=item['is_licensed'],
# license_information=item['license_information'],
# insured_value=item['insured_value'],
# bond_value=item['bond_value'],
# address=item['address'],
# last_update_date=item['last_update_date'],
# workers_info=item['workers_info'],
# image='images/' + item['images'][0]['path'],
# imageurl=item['images'][0]['url'])
# db.add(record)
# try:
# db.commit()
# except IntegrityError:
# db.rollback()
# raise DropItem("Duplicate entry.")
return item
# Automatically created by: scrapy startproject
#
# For more information about the [deploy] section see:
# https://scrapyd.readthedocs.io/en/latest/deploy.html
[settings]
default = settings
[deploy]
#url = http://localhost:6800/
project = buildzoom_parser
import os
from dotenv import load_dotenv
# -*- coding: utf-8 -*-
# Scrapy settings for buildzoom_parser project
#
# For simplicity, this file contains only settings considered important or
# commonly used. You can find more settings consulting the documentation:
#
# https://docs.scrapy.org/en/latest/topics/settings.html
# https://docs.scrapy.org/en/latest/topics/downloader-middleware.html
# https://docs.scrapy.org/en/latest/topics/spider-middleware.html
load_dotenv()
BOT_NAME = "buildzoom_parser"
SPIDER_MODULES = ["spiders"]
NEWSPIDER_MODULE = "spiders"
# Crawl responsibly by identifying yourself (and your website) on the user-agent
# USER_AGENT = 'buildzoom_parser (+http://www.yourdomain.com)'
# Obey robots.txt rules
# ROBOTSTXT_OBEY = True
# Configure maximum concurrent requests performed by Scrapy (default: 16)
CONCURRENT_REQUESTS = os.getenv("CONCURRENT_REQUESTS")
# Configure a delay for requests for the same website (default: 0)
# See https://docs.scrapy.org/en/latest/topics/settings.html#download-delay
# See also autothrottle settings and docs
DOWNLOAD_DELAY = os.getenv("DOWNLOAD_DELAY")
# 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,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "en-US",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.165 Safari/537.36",
}
# Enable or disable spider middlewares
# See https://docs.scrapy.org/en/latest/topics/spider-middleware.html
# SPIDER_MIDDLEWARES = {
# 'buildzoom_parser.middlewares.BuildzoomParserSpiderMiddleware': 543,
# }
# Enable or disable downloader middlewares
# See https://docs.scrapy.org/en/latest/topics/downloader-middleware.html
DOWNLOADER_MIDDLEWARES = {
'middlewares.middlewares.BuildzoomParserDownloaderMiddleware': 350,
'scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware': 400,
}
# Enable or disable extensions
# See https://docs.scrapy.org/en/latest/topics/extensions.html
# EXTENSIONS = {
# 'scrapy.extensions.telnet.TelnetConsole': None,
# }
# Configure item pipelines
# See https://docs.scrapy.org/en/latest/topics/item-pipeline.html
ITEM_PIPELINES = {
'scrapy.pipelines.images.ImagesPipeline': 1,
'pipelines.pipelines.BusinessPipeline': 300,
}
IMAGES_STORE = 'images'
# Enable and configure the AutoThrottle extension (disabled by default)
# See https://docs.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://docs.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'
# -*- coding: utf-8 -*-
import scrapy
from scrapy.spiders import Spider
class BuildzoomSitemapSpider(Spider):
name = "sitemap"
def start_requests(self):
start_urls = ["https://www.buildzoom.com/sitemap.xml"]
for url in start_urls:
yield scrapy.Request(url, callback=self.parse_sitemap)
def parse_sitemap(self, response: scrapy.http.Response):
text = response.xpath('.//text()').getall()
for link in text:
if "contractors" in link:
yield scrapy.Request(link, callback=self.parse_contractor_urls)
def parse_contractor_urls(self, response):
text = response.xpath('.//text()').getall()
for link in text:
if "contractors" in link:
yield {
'link': link
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment