-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from jiangwei1995910/ziroom
自如爬虫
- Loading branch information
Showing
10 changed files
with
414 additions
and
34 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,16 +1,16 @@ | ||
import pymysql | ||
import datetime | ||
|
||
from config import DBInfo | ||
|
||
# 打开数据库连接 | ||
db = pymysql.connect("localhost","root","78667602" ,"zhaopin") | ||
db = pymysql.connect(DBInfo.dbhost, DBInfo.user, DBInfo.pwd, DBInfo.db) | ||
|
||
# 使用 cursor() 方法创建一个游标对象 cursor | ||
cursor = db.cursor() | ||
|
||
today=datetime.date.today() | ||
today = datetime.date.today() | ||
# 使用 execute() 方法执行 SQL 查询 | ||
cursor.execute("CREATE TABLE `近12月生活压力_"+str(today)+"` AS SELECT * FROM `近12月生活压力` WHERE gfyl is NOT null;") | ||
|
||
|
||
cursor.execute("CREATE TABLE `近12月生活压力_" + str(today) + "` AS SELECT * FROM `近12月生活压力` WHERE gfyl is NOT null;") | ||
|
||
# 关闭数据库连接 | ||
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 |
---|---|---|
@@ -1,16 +1,20 @@ | ||
#coding:utf-8 | ||
# coding:utf-8 | ||
from sqlalchemy import create_engine | ||
from sqlalchemy.orm import sessionmaker | ||
|
||
dbhost = "127.0.0.1" | ||
port = '3306' | ||
db = 'zhaopin' | ||
pwd = '78667602' | ||
user = 'root' | ||
|
||
|
||
#数据库设置 | ||
# 数据库设置 | ||
engine = create_engine( | ||
"mysql+pymysql://root:[email protected]:3306/zhaopin?charset=utf8", | ||
max_overflow=20, # 超过连接池大小外最多创建的连接 | ||
pool_size=10, # 连接池大小 | ||
pool_timeout=30, # 池中没有线程最多等待的时间,否则报错 | ||
pool_recycle=-1 # 多久之后对线程池中的线程进行一次连接的回收(重置) | ||
) | ||
"mysql+pymysql://" + user + ":" + pwd + "@" + dbhost + ":" + port + "/" + db + "?charset=utf8", | ||
max_overflow=20, # 超过连接池大小外最多创建的连接 | ||
pool_size=10, # 连接池大小 | ||
pool_timeout=30, # 池中没有线程最多等待的时间,否则报错 | ||
pool_recycle=-1 # 多久之后对线程池中的线程进行一次连接的回收(重置) | ||
) | ||
|
||
SessionFactory = sessionmaker(bind=engine) | ||
SessionFactory = sessionmaker(bind=engine) |
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 |
---|---|---|
@@ -1,6 +1,11 @@ | ||
# m h dom mon dow command | ||
50 3 * * 2 /home/jiangwei1995910/lianjia-beike-spider/run.sh | ||
0 18 * * * /home/jiangwei1995910/getAwayBSG/run.sh | ||
# 启动链家爬虫 | ||
0 16 * * * /home/jiangwei1995910/getAwayBSG/run.sh | ||
# 启动智联爬虫 | ||
0 0 * * * /usr/bin/python3 /home/jiangwei1995910/getAwayBSG/main.py | ||
# 每个月11号备份视图数据 | ||
* * 11 * * /usr/bin/python3 /home/jiangwei1995910/getAwayBSG/backup.py | ||
# 每天早上8点和中午13点汇报服务器状态 | ||
0 8,13 * * * /usr/bin/python3 /home/jiangwei1995910/getAwayBSG/reportIP.py | ||
# 自如爬虫 | ||
0 8 * * * /usr/bin/python3 /home/jiangwei1995910/getAwayBSG/spider/ziroom.py |
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,44 @@ | ||
#coding:utf-8 | ||
from sqlalchemy.ext.declarative import declarative_base | ||
from sqlalchemy import Column, String, Integer, Float, DateTime | ||
|
||
|
||
# 创建对象的基类: | ||
Base = declarative_base() | ||
|
||
class Ziroom(Base): | ||
# 表的名字: | ||
__tablename__ = 'ziroom' | ||
|
||
# 表的结构: | ||
id = Column(Integer, primary_key=True) | ||
price = Column(Integer()) | ||
url = Column(String(255)) | ||
iswhole = Column(Integer()) | ||
area = Column(Float()) | ||
bedroom = Column(String(2)) | ||
parlor = Column(String(2)) | ||
district_name = Column(String(15)) | ||
bizcircle_name = Column(String(15)) | ||
|
||
|
||
def __init__(self,data): | ||
for key in data.keys(): | ||
if key == 'id': | ||
self.id=data[key] | ||
if key == 'price': | ||
self.price=data[key] | ||
if key == 'url': | ||
self.url=data[key] | ||
if key == 'iswhole': | ||
self.iswhole=data[key] | ||
if key == 'area': | ||
self.area=data[key] | ||
if key == 'bedroom': | ||
self.bedroom=data[key] | ||
if key == 'parlor': | ||
self.parlor=data[key] | ||
if key == 'district_name': | ||
self.district_name=data[key] | ||
if key == 'bizcircle_name': | ||
self.bizcircle_name=data[key] |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
requests | ||
SQLAlchemy | ||
scrapy | ||
pymysql | ||
pymysql | ||
pyquery |
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
Oops, something went wrong.