You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
144 lines
5.1 KiB
144 lines
5.1 KiB
# -*- coding: utf-8 -*-
|
|
|
|
# Scrapy settings for bot 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
|
|
import sys
|
|
import os
|
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'weibosystem.settings'
|
|
sys.path.append(os.path.dirname(os.path.abspath('.')))
|
|
|
|
import django
|
|
django.setup()
|
|
|
|
import random
|
|
import pymysql.cursors
|
|
# 连接数据库
|
|
connect = pymysql.connect(
|
|
host='localhost', # 数据库地址
|
|
port=3306, # 数据库端口
|
|
db='WeiboAnalysisSystem', # 数据库名
|
|
user='root', # 数据库用户名
|
|
passwd='1234', # 数据库密码
|
|
charset='utf8mb4', # 编码方式
|
|
use_unicode=True)
|
|
# 通过cursor执行增删查改
|
|
cursor = connect.cursor()
|
|
cursor.execute("""SELECT cookie from scrapydapi_target""")
|
|
cookie = cursor.fetchall()
|
|
connect.close()
|
|
cursor.close()
|
|
listCookie = []
|
|
for res1 in cookie:
|
|
listCookie.append(res1)
|
|
random.shuffle(listCookie)
|
|
|
|
BOT_NAME = 'bot'
|
|
|
|
SPIDER_MODULES = ['bot.spiders']
|
|
NEWSPIDER_MODULE = 'bot.spiders'
|
|
|
|
# 请将Cookie替换成你自己的Cookie
|
|
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',
|
|
'Accept-Encoding': 'gzip, deflate, br',
|
|
'Accept-Language': 'zh-CN,zh;q=0.9',
|
|
'Connection': 'keep-alive',
|
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36',
|
|
'Cookie': '_T_WM=50363706066; _WEIBO_UID=1797112632; _T_WL=1; TMPTOKEN=bxCuDsiKUQY2sOT9Le88wAefIoC875Bo0Db2mrn7UD5D3PBj5Y2S3HsCDFJAxh28; ALF=1559406008; SCF=AoLtbFF76lqGJoGS67xfWdN25HiipYMS8RNOsQP8J1SmIgi7wHRoWF5Qz2aNpJhwRdzeFkELxt8cM1MOzq8TtZ4.; SUB=_2A25xz2jpDeRhGeBL7VYT-CzMyj-IHXVTMAihrDV6PUNbktAKLRWgkW1NRvot3YHElYQeX7nzuJ-_wPy29U4vS5Gr; SUBP=0033WrSXqPxfM725Ws9jqgMF55529P9D9W5M6cF8H3lRRyK.ZidI-eTX5JpX5KzhUgL.FoqfSoBE1hz7eKe2dJLoIERLxK-L12qLB-qLxKBLBo.L1K5LxK-L122LBK5LxK-L1K2LBoeLxKMLBozLB.Hp; SUHB=04W-N46VY7mi75; SSOLoginState=1556814010'
|
|
}
|
|
|
|
# 当前是单账号,所以下面的 CONCURRENT_REQUESTS 和 DOWNLOAD_DELAY 请不要修改
|
|
|
|
CONCURRENT_REQUESTS = 16
|
|
|
|
DOWNLOAD_DELAY = 3
|
|
|
|
DOWNLOADER_MIDDLEWARES = {
|
|
'weibo.middlewares.UserAgentMiddleware': None,
|
|
'scrapy.downloadermiddlewares.cookies.CookiesMiddleware': None,
|
|
'scrapy.downloadermiddlewares.redirect.RedirectMiddleware': None
|
|
}
|
|
|
|
ITEM_PIPELINES = {
|
|
'bot.pipelines.BotPipeline': 300,
|
|
}
|
|
# Crawl responsibly by identifying yourself (and your website) on the user-agent
|
|
#USER_AGENT = 'bot (+http://www.yourdomain.com)'
|
|
|
|
# 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 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 = {
|
|
# 'bot.middlewares.BotSpiderMiddleware': 543,
|
|
#}
|
|
|
|
# Enable or disable downloader middlewares
|
|
# See https://doc.scrapy.org/en/latest/topics/downloader-middleware.html
|
|
#DOWNLOADER_MIDDLEWARES = {
|
|
# 'bot.middlewares.BotDownloaderMiddleware': 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 = {
|
|
# 'bot.pipelines.BotPipeline': 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'
|