<reponame>vivCoding/vsearch<gh_stars>0
# Scrapy settings for webscraper 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

import os
from dotenv import load_dotenv
load_dotenv()

BOT_NAME = 'webscraper'

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

# Obey robots.txt rules
ROBOTSTXT_OBEY = True

# Configure maximum concurrent requests performed by Scrapy (default: 16)
CONCURRENT_REQUESTS = 100

# 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 = 2
# The download delay setting will honor only one of:
CONCURRENT_REQUESTS_PER_DOMAIN = 30
# 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://docs.scrapy.org/en/latest/topics/spider-middleware.html
#SPIDER_MIDDLEWARES = {
#    'webscraper.middlewares.WebscraperSpiderMiddleware': 543,
#}

# Crawl responsibly by identifying yourself (and your website) on the user-agent
#USER_AGENT = 'webscraper (+http://www.yourdomain.com)'

# Enable or disable downloader middlewares
# See https://docs.scrapy.org/en/latest/topics/downloader-middleware.html
# Random user agent with https://pypi.org/project/scrapy-user-agents/
# Random proxies with https://github.com/TeamHG-Memex/scrapy-rotating-proxies
RANDOM_UA_PER_PROXY = True
if ua_file := os.getenv("RANDOM_UA_FILE", None):
    RANDOM_UA_FILE = ua_file
DOWNLOADER_MIDDLEWARES = {
    'scrapy.downloadermiddlewares.useragent.UserAgentMiddleware': None,
    'scrapy_user_agents.middlewares.RandomUserAgentMiddleware': 400,
    'rotating_proxies.middlewares.RotatingProxyMiddleware': 610,
    'rotating_proxies.middlewares.BanDetectionMiddleware': 620,
}
if proxy_list := os.getenv("ROTATING_PROXY_LIST_PATH", None):
    ROTATING_PROXY_LIST_PATH = proxy_list
ROTATING_PROXY_PAGE_RETRY_TIMES = 5
ROTATING_PROXY_BACKOFF_BASE = 210
ROTATING_PROXY_BACKOFF_CAP = 1800

# 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 = {
   'webscraper.pipelines.ParserPipeline': 1,
   'webscraper.pipelines.MongoPipeline': 2,
}

# 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 = 1
# # The maximum download delay to be set in case of high latencies
# AUTOTHROTTLE_MAX_DELAY = 4
# # The average number of requests Scrapy should be sending in parallel to
# # each remote server
# AUTOTHROTTLE_TARGET_CONCURRENCY = 30
# 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'

# Additional settings for broad crawls
# See (https://docs.scrapy.org/en/latest/topics/broad-crawls.html)

SCHEDULER_PRIORITY_QUEUE = 'scrapy.pqueues.DownloaderAwarePriorityQueue'
REACTOR_THREADPOOL_MAXSIZE = 50

# go in breadth-first-order rather than depth first
DEPTH_PRIORITY = 1
SCHEDULER_DISK_QUEUE = 'scrapy.squeues.PickleFifoDiskQueue'
SCHEDULER_MEMORY_QUEUE = 'scrapy.squeues.FifoMemoryQueue'

# DEPTH_LIMIT = 1
DEPTH_STATS_VERBOSE = True
CONCURRENT_ITEMS = 100

DOWNLOAD_TIMEOUT = 30
RETRY_ENABLED = False
REDIRECT_ENABLED = True
REDIRECT_MAX_TIMES = 3

LOG_LEVEL = 'INFO'
# LOG_FILE = "logs.txt"

# Custom dupe filter
DUPEFILTER_CLASS = 'webscraper.middlewares.DupeFilter'

# remember, don't set this too high, because Mongo max doc size is 16 MB
DB_BUFFER_SIZE = 1000
DB_UPLOAD_DELAY = 0
UPLOAD_TOKENS = True
# Scrapy settings for webscraper 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

import os
from dotenv import load_dotenv
load_dotenv()

BOT_NAME = 'webscraper'

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

# Obey robots.txt rules
ROBOTSTXT_OBEY = True

# Configure maximum concurrent requests performed by Scrapy (default: 16)
CONCURRENT_REQUESTS = 100

# 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 = 2
# The download delay setting will honor only one of:
CONCURRENT_REQUESTS_PER_DOMAIN = 30
# 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://docs.scrapy.org/en/latest/topics/spider-middleware.html
#SPIDER_MIDDLEWARES = {
#    'webscraper.middlewares.WebscraperSpiderMiddleware': 543,
#}

# Crawl responsibly by identifying yourself (and your website) on the user-agent
#USER_AGENT = 'webscraper (+http://www.yourdomain.com)'

# Enable or disable downloader middlewares
# See https://docs.scrapy.org/en/latest/topics/downloader-middleware.html
# Random user agent with https://pypi.org/project/scrapy-user-agents/
# Random proxies with https://github.com/TeamHG-Memex/scrapy-rotating-proxies
RANDOM_UA_PER_PROXY = True
if ua_file := os.getenv("RANDOM_UA_FILE", None):
    RANDOM_UA_FILE = ua_file
DOWNLOADER_MIDDLEWARES = {
    'scrapy.downloadermiddlewares.useragent.UserAgentMiddleware': None,
    'scrapy_user_agents.middlewares.RandomUserAgentMiddleware': 400,
    'rotating_proxies.middlewares.RotatingProxyMiddleware': 610,
    'rotating_proxies.middlewares.BanDetectionMiddleware': 620,
}
if proxy_list := os.getenv("ROTATING_PROXY_LIST_PATH", None):
    ROTATING_PROXY_LIST_PATH = proxy_list
ROTATING_PROXY_PAGE_RETRY_TIMES = 5
ROTATING_PROXY_BACKOFF_BASE = 210
ROTATING_PROXY_BACKOFF_CAP = 1800

# 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 = {
   'webscraper.pipelines.ParserPipeline': 1,
   'webscraper.pipelines.MongoPipeline': 2,
}

# 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 = 1
# # The maximum download delay to be set in case of high latencies
# AUTOTHROTTLE_MAX_DELAY = 4
# # The average number of requests Scrapy should be sending in parallel to
# # each remote server
# AUTOTHROTTLE_TARGET_CONCURRENCY = 30
# 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'

# Additional settings for broad crawls
# See (https://docs.scrapy.org/en/latest/topics/broad-crawls.html)

SCHEDULER_PRIORITY_QUEUE = 'scrapy.pqueues.DownloaderAwarePriorityQueue'
REACTOR_THREADPOOL_MAXSIZE = 50

# go in breadth-first-order rather than depth first
DEPTH_PRIORITY = 1
SCHEDULER_DISK_QUEUE = 'scrapy.squeues.PickleFifoDiskQueue'
SCHEDULER_MEMORY_QUEUE = 'scrapy.squeues.FifoMemoryQueue'

# DEPTH_LIMIT = 1
DEPTH_STATS_VERBOSE = True
CONCURRENT_ITEMS = 100

DOWNLOAD_TIMEOUT = 30
RETRY_ENABLED = False
REDIRECT_ENABLED = True
REDIRECT_MAX_TIMES = 3

LOG_LEVEL = 'INFO'
# LOG_FILE = "logs.txt"

# Custom dupe filter
DUPEFILTER_CLASS = 'webscraper.middlewares.DupeFilter'

# remember, don't set this too high, because Mongo max doc size is 16 MB
DB_BUFFER_SIZE = 1000
DB_UPLOAD_DELAY = 0
UPLOAD_TOKENS = True
# Scrapy settings for webscraper 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 # Obey robots.txt rules # Configure maximum concurrent requests performed by Scrapy (default: 16) # 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 # The download delay setting will honor only one of: # CONCURRENT_REQUESTS_PER_IP = 16 # Disable cookies (enabled by default) # Disable Telnet Console (enabled by default) # Override the default request headers: # Enable or disable spider middlewares # See https://docs.scrapy.org/en/latest/topics/spider-middleware.html #SPIDER_MIDDLEWARES = { #    'webscraper.middlewares.WebscraperSpiderMiddleware': 543, #} # Crawl responsibly by identifying yourself (and your website) on the user-agent #USER_AGENT = 'webscraper (+http://www.yourdomain.com)' # Enable or disable downloader middlewares # See https://docs.scrapy.org/en/latest/topics/downloader-middleware.html # Random user agent with https://pypi.org/project/scrapy-user-agents/ # Random proxies with https://github.com/TeamHG-Memex/scrapy-rotating-proxies # 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 # 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 = 1 # # The maximum download delay to be set in case of high latencies # AUTOTHROTTLE_MAX_DELAY = 4 # # The average number of requests Scrapy should be sending in parallel to # # each remote server # AUTOTHROTTLE_TARGET_CONCURRENCY = 30 # 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' # Additional settings for broad crawls # See (https://docs.scrapy.org/en/latest/topics/broad-crawls.html) # go in breadth-first-order rather than depth first # DEPTH_LIMIT = 1 # LOG_FILE = "logs.txt" # Custom dupe filter # remember, don't set this too high, because Mongo max doc size is 16 MB