-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1c216c9
Showing
16 changed files
with
592 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from scrapy import cmdline | ||
|
||
# cmdline.execute('scrapy crawl LagoSpider'.split()) | ||
cmdline.execute('scrapy crawl LagoSpider_redisSpider'.split()) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 JobspiderLagoItem(scrapy.Item): | ||
# define the fields for your item here like: | ||
keyword = scrapy.Field() | ||
jobData = scrapy.Field() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 JobspiderLagoSpiderMiddleware(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 JobspiderLagoDownloaderMiddleware(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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# -*- 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 | ||
|
||
|
||
from JobSpider_lago.settings import * | ||
import pymysql | ||
|
||
|
||
# 最开始的pipeline | ||
class JobspiderLagoPipelineDefault(object): | ||
|
||
def process_item(self, item, spider): | ||
return item | ||
|
||
|
||
class JobspiderLagoPipelineMySql(object): | ||
|
||
def open_spider(self, spider): | ||
self.db = pymysql.connect(host=MYSQLHOST, user=MYSQLUSER, password=MYSQLPASSWORD, db=MYSQLDATABASE, | ||
port=MYSQLPORT, charset='utf8') | ||
self.cu = self.db.cursor() | ||
|
||
def process_item(self, item, spider): | ||
jobData = item['jobData'] | ||
data = [ | ||
item['keyword'], | ||
jobData['所在城市'], | ||
jobData['公司氛围'], | ||
jobData['公司规模'], | ||
jobData['是否上市'], | ||
jobData['第一工作分类'], | ||
jobData['工作性质'], | ||
jobData['工作优势'], | ||
jobData['工作技能要求'], | ||
jobData['工作名称'], | ||
jobData['工资'], | ||
jobData['第二工作分类'], | ||
jobData['第三工作分类'], | ||
jobData['工作年限要求'] | ||
] | ||
try: | ||
self.cu.execute( | ||
'insert into jobInfo( ' | ||
'keyword, city, companyLabelList, companySize, financeStage, firstType, jobNature,' | ||
'positionAdvantage, positionLables, positionName, salary, secondType, thirdType, workYear' | ||
')values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)', data | ||
) | ||
except Exception as e: | ||
print(e) | ||
self.db.rollback() | ||
else: | ||
self.db.commit() | ||
|
||
return item | ||
|
||
def close_spider(self, spider): | ||
self.cu.close() | ||
self.db.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Scrapy settings for JobSpider_lago 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 = 'JobSpider_lago' | ||
|
||
SPIDER_MODULES = ['JobSpider_lago.spiders'] | ||
NEWSPIDER_MODULE = 'JobSpider_lago.spiders' | ||
|
||
LOG_LEVEL = 'DEBUG' | ||
|
||
# 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/77.0.3865.120 Safari/537.36' | ||
|
||
# Obey robots.txt rules | ||
ROBOTSTXT_OBEY = False | ||
|
||
# MYSQL INFO | ||
MYSQLHOST = 'localhost' | ||
MYSQLUSER = 'root' | ||
MYSQLPASSWORD = '123456' | ||
MYSQLDATABASE = 'testdb' | ||
MYSQLPORT = 3306 | ||
|
||
# Redis INFO | ||
REDIS_URL = 'redis://localhost:6379' | ||
# REDIS_HOST = 'localhost' | ||
# REDIS_POST = '6379' | ||
# redis的去重类 | ||
DUPEFILTER_CLASS = "scrapy_redis.dupefilter.RFPDupeFilter" | ||
# redis使用的调度器 | ||
SCHEDULER = "scrapy_redis.scheduler.Scheduler" | ||
# 调度器保留请求过的url(增量式爬虫,断点续爬) | ||
SCHEDULER_PERSIST = True | ||
# 设置 redis 编码方法 | ||
REDIS_ENCODING = 'utf-8' | ||
# redis 密码 | ||
# REDIS_PARAMS = {'password':'123456'} | ||
|
||
# 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 = { | ||
# 'JobSpider_lago.middlewares.JobspiderLagoSpiderMiddleware': 543, | ||
# } | ||
|
||
# Enable or disable downloader middlewares | ||
# See https://doc.scrapy.org/en/latest/topics/downloader-middleware.html | ||
# DOWNLOADER_MIDDLEWARES = { | ||
# 'JobSpider_lago.middlewares.JobspiderLagoDownloaderMiddleware': 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 = { | ||
'JobSpider_lago.pipelines.JobspiderLagoPipelineDefault': 100, | ||
# 'JobSpider_lago.pipelines.JobspiderLagoPipelineMySql': 300, | ||
'scrapy_redis.pipelines.RedisPipeline': 400, # 使用Redis内置保存数据的pipline | ||
} | ||
|
||
# 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' |
Oops, something went wrong.