Cloudmistery 6 mesiacov pred
rodič
commit
1c99e44a3b

BIN
utils/__pycache__/anjuke_response.cpython-39.pyc


BIN
utils/__pycache__/get_message.cpython-39.pyc


BIN
utils/__pycache__/get_price.cpython-39.pyc


BIN
utils/__pycache__/logger.cpython-39.pyc


BIN
utils/__pycache__/mysqlClass.cpython-39.pyc


BIN
utils/__pycache__/setting.cpython-39.pyc


BIN
utils/__pycache__/sql_anjuke.cpython-39.pyc


+ 1 - 1
utils/anjuke_response.py

@@ -10,4 +10,4 @@ from anjuke.utils.setting import *
 response_origion = requests.get(url = url_start, headers=headers,proxies=proxies, timeout=10).content.decode('utf8')
 response_200 = requests.get(url = url_start, headers=headers,proxies=proxies, timeout=10)
 
-print(response_origion,response_200)
+print(response_origion,response_200)

+ 75 - 25
utils/get_message.py

@@ -6,35 +6,62 @@
 from bs4 import BeautifulSoup
 from anjuke.utils.anjuke_response import *
 from anjuke.utils.setting import *
-import time,random
+from anjuke.utils.mysqlClass import *
+import mysql.connector
+
 # 省级
 def get_province():
+    name = 'province'
     province_name_list = []
     province_url_list = []
-    response_province = requests.get(url = url_start, headers = headers, proxies=proxies, timeout=10).content.decode('utf8')
-    time.sleep(random.uniform(0.5, 1))
+    response_province = requests.get(url = url_start, headers = headers, proxies=proxies).content.decode('utf8')
     soup = BeautifulSoup(response_province, 'html.parser')
-    # print(soup)
     filter_area_wrap = soup.find(class_="filter-area-wrap")
-    # print(filter_area_wrap)
     for province_ in filter_area_wrap.find_all('a'):
         province_name = province_.text
         province_url = province_.get('href')
         province_name_list.append(province_name)
         province_url_list.append('https://www.anjuke.com'+province_url)
     del province_name_list[0],province_url_list[0]
+
+    # 创建游标对象,用于执行SQL查询
+
+    cursor1 = db.cursor()
+    for i in range(len(province_name_list)):
+        # 插入一条记录到"anjuke_province"表中
+        sql = "INSERT INTO anjuke_province (place_name,place_url) VALUES (%s,%s)"
+        values = (province_name_list[i], province_url_list[i])
+        cursor1.execute(sql, values)
+        # 提交更改到数据库
+        db.commit()
+        print(f"插入了 {cursor1.rowcount} 条记录")
+    cursor1.close()
+
+    print(f'已获取并添加全部省级单位')
     return province_name_list,province_url_list
 
 # 市级
 def get_city():
-    province_name_list,province_url_list = get_province()
+    name = 'city'
+    # 设置空列表
     city_name_list = []
     city_url_list = []
-    for i in range(len(province_url_list)):
-        province_url = province_url_list[i]
-        province_name = province_name_list[i]
-        response_city = requests.get(url = province_url, headers = headers, proxies=proxies, timeout=10).content.decode('utf8')
-        time.sleep(random.uniform(3, 4))
+    # 设置游标cursor
+    cursor2 = db.cursor()
+    # 传参
+    query = "SELECT * FROM anjuke_province"
+    cursor2.execute(query)
+    results = cursor2.fetchall()
+    province_list = [list(row) for row in results]
+    # 记得关掉cursor
+    cursor2.close()
+
+    # 开始循环
+    print('开始循环省份-城市')
+    for i in range(len(province_list)):
+        province_name = province_list[i][0]
+        province_url = province_list[i][1]
+        response_city = requests.get(url = province_url, headers = headers, proxies=proxies).content.decode('utf8')
         soup = BeautifulSoup(response_city, 'html.parser')
         filter_area_wrap = soup.find(class_="sel-content bank")
         zhongji_name_list = []
@@ -47,20 +74,35 @@ def get_city():
         del zhongji_name_list[0], zhongji_url_list[0]
         city_name_list += zhongji_name_list
         city_url_list += zhongji_url_list
-        print(f'已循环到第{i}个省级单位:{province_name_list[i]}')
+
+        # # 上传代码
+        # cursor2 = db.cursor()
+        # for i in range(len(city_name_list)):
+        #     # 插入一条记录到"anjuke_province"表中
+        #     sql = "INSERT INTO anjuke_city (place_name,place_url) VALUES (%s,%s)"
+        #     values = (city_name_list[i], city_url_list[i])
+        #     cursor2.execute(sql, values)
+        #     # 提交更改到数据库
+        #     db.commit()
+        #     print(f"插入了 {cursor2.rowcount} 条记录")
+        #     print(f"插入了 {i} 条记录")
+        # cursor2.close()
+
+        print(f'已循环到第{i}个省级单位:{province_name}')
+    print(city_name_list)
     return city_name_list,city_url_list
 
 # 区级
 def get_area():
+    name = 'area'
     city_name_list, city_url_list = get_city()
     area_name_list = []
     area_url_list = []
-
+    print('开始循环城市-区域')
     for i in range(len(city_url_list)):
         city_url = city_url_list[i]
         city_name = city_name_list[i]
-        response_area = requests.get(url = city_url, headers = headers ,proxies=proxies, timeout=10).content.decode('utf8')
-        time.sleep(random.uniform(2, 3))
+        response_area = requests.get(url = city_url, headers = headers ,proxies=proxies).content.decode('utf8')
         soup = BeautifulSoup(response_area, 'html.parser')
         filter_area_wrap = soup.find(class_="sel-content bank")
         zhongji_name_list = []
@@ -70,32 +112,37 @@ def get_area():
             area_url = area_.get('href')
             zhongji_name_list.append(area_name)
             zhongji_url_list.append(area_url)
-            area_name_list.append(area_name)
-            area_url_list.append(area_url)
-        del area_name_list[0],area_url_list[0]
+        del zhongji_name_list[0],zhongji_url_list[0]
+        area_name_list += zhongji_name_list
+        area_url_list += zhongji_url_list
+        print(f'已循环到第{i}个市级单位:{city_name_list[i]}')
     return area_name_list,area_url_list
 
 
 # 周边
 def get_periphery():
+    name = 'periphery'
     area_name_list, area_url_list = get_area()
     periphery_name_list = []
     periphery_url_list = []
-
+    print('开始循环区域-周边')
     for i in range(len(area_url_list)):
         area_url = area_url_list[i]
         area_name = area_name_list[i]
-        response_periphery = requests.get(url = area_url, headers = headers ,proxies=proxies, timeout=10).content.decode('utf8')
-        time.sleep(random.uniform(3, 5))
+        response_periphery = requests.get(url = area_url, headers = headers ,proxies=proxies).content.decode('utf8')
         soup = BeautifulSoup(response_periphery, 'html.parser')
         filter_area_wrap = soup.find(class_="sel-content bank")
+        zhongji_name_list = []
+        zhongji_url_list = []
         for periphery_ in filter_area_wrap.find_all('a'):
             periphery_name = area_name + periphery_.text
             periphery_url = periphery_.get('href')
-            periphery_name_list.append(periphery_name)
-            periphery_url_list.append(periphery_url)
+            zhongji_name_list.append(periphery_name)
+            zhongji_url_list.append(periphery_url)
         del periphery_name_list[0], periphery_url_list[0]
-        time.sleep(random.uniform(3, 5))
+        periphery_name_list += zhongji_name_list
+        periphery_url_list += zhongji_url_list
+        print(f'已循环到第{i}个周边单位:{area_name_list[i]}')
     return periphery_name_list, periphery_url_list
 
 # 获取年份
@@ -108,7 +155,10 @@ def get_Year():
         Years_list.append(year)
     return Years_list
 
-# 测试函数
+# 创建mysql数据库方法
+
+
+# # 测试函数
 if __name__ == '__main__':
     # print('时间跨度:',get_Year())
     # print('省级单位:',get_province())

+ 9 - 5
utils/get_price.py

@@ -35,16 +35,20 @@ def get_price():
                 'div', class_="up") or table_tr.find('div', class_="down")
             attr = UporDown['class'][0]
             if attr == "up":
-                tab = ''
+                tab = 'UP'
             elif attr == "down":
-                tab = ''
+                tab = 'DOWN'
             else:
-                tab = '-'
+                tab = 'CONSTANT'
             zhongji.insert(2,tab)
             list1.append(zhongji)
             list1.append(name)
         result.append(list1)
     return result
 
-if __name__ == '__main__':
-    get_price()
+
+
+# if __name__ == '__main__':
+    # connectMysql()
+    # get_price()
+    # closeMysql(conn = )

+ 0 - 0
utils/log/Uncaught_exception.log_20241014.log


+ 0 - 0
utils/log/Uncaught_exception.log_20241015.log


+ 158 - 0
utils/logger.py

@@ -0,0 +1,158 @@
+# -*- encoding: utf-8 -*-
+'''
+@File    :   logger.py
+@Time    :   2022/05/10 10:54:26
+@Author  :   Zhangziheng
+'''
+import datetime
+import inspect
+import io
+import logging
+import os
+import platform
+
+# == 判断日志文件夹是否存在 不存在则创建 ==
+if not os.path.exists('log'):
+    os.mkdir('log', 0o775)
+
+
+def creatLogger(name):
+    """创建logger
+
+    Args:
+        name (string): 打印者的名称
+
+    Returns:
+        logger
+    """
+    datefmt = '%Y-%m-%d %H:%M:%S'
+    logging.basicConfig(
+        level=logging.INFO,
+        datefmt=datefmt,
+        format='[%(asctime)s] [%(process)d] [%(levelname)s] :: %(message)s')
+    return logging.getLogger(name)
+
+
+class Logger(object):
+    level_relations = {
+        'debug': logging.DEBUG,
+        'info': logging.INFO,
+        'warning': logging.WARNING,
+        'error': logging.ERROR,
+        'crit': logging.CRITICAL
+    }  # 日志级别关系映射
+
+    def __init__(
+        self,
+        filename,
+        level='info',
+        fmt='%(asctime)s - %(levelname)s: %(message)s'
+    ):
+        self.filename = filename
+        self.level = level
+        self.fmt = fmt
+        self.logger = logging.getLogger(filename)
+        self.logger.setLevel(self.level_relations.get(level))  # 设置日志级别
+        self._set_handler()
+
+    def _set_handler(self):
+        self.current_date = datetime.datetime.now().strftime('%Y%m%d')  # 更新当前的日期
+        filename_with_date = f"{self.filename}_{self.current_date}.log"
+        sh = logging.StreamHandler()  # 往屏幕上输出
+        format_str = logging.Formatter(self.fmt)  # 设置日志格式
+        sh.setFormatter(format_str)  # 设置屏幕上显示的格式
+        th = logging.FileHandler(filename_with_date, encoding='utf-8')
+        th.setFormatter(format_str)  # 设置文件里写入的格式
+        if self.logger.hasHandlers():
+            self.logger.handlers.clear()
+        self.logger.addHandler(sh)  # 把对象加到logger里
+        self.logger.addHandler(th)
+
+    def get_stream_handler(self):
+        """返回一个设置了格式和级别的日志处理器,并且这个处理器会将日志输出到一个字符串流中"""
+
+        stream = io.StringIO()
+        sh = logging.StreamHandler(stream)  # 往字符串流中输出
+        format_str = logging.Formatter(self.fmt)  # 设置日志格式
+        sh.setFormatter(format_str)  # 设置字符串流中显示的格式
+        sh.setLevel(self.level_relations.get(self.level))  # 设置日志级别
+        return sh, stream
+
+    def debug(self, message):
+        self._check_and_set_handler()
+        self._log('debug', message)
+
+    def info(self, message):
+        self._check_and_set_handler()
+        self._log('info', message)
+
+    def warning(self, message):
+        self._check_and_set_handler()
+        self._log('warning', message)
+
+    def error(self, message):
+        self._check_and_set_handler()
+        self._log('error', message)
+
+    def crit(self, message):
+        self._check_and_set_handler()
+        self._log('critical', message)
+
+    def _log(self, level, message):
+        caller_frame = inspect.stack()[2]
+        file_name = caller_frame.filename
+        line_no = caller_frame.lineno
+        func_name = caller_frame.function
+        self.logger.log(
+            self.level_relations[level], f'{file_name}[line:{line_no}] - {func_name}: {message}')
+
+    def _check_and_set_handler(self):
+        current_date = datetime.datetime.now().strftime('%Y%m%d')
+        if current_date != self.current_date:  # 检查当前的日期是否与FileHandler的日期一致
+            self._set_handler()
+
+
+class bbLoger(object):
+    def __init__(self, name, errorName):
+        self.logger = creatLogger(name)
+        # self.errorLogger = Logger(errorName)
+        self._ggg_Uncaught_exception = Logger(errorName)
+
+    def info(self, messgae):
+        self.logger.info(messgae)
+
+    def waring(self, messgae):
+        self.logger.warning(messgae)
+
+    def error(self, messgae):
+        self.logger.error(messgae)
+        # self.errorLogger.logger.error(messgae)
+        self._ggg_Uncaught_exception .error(messgae)
+
+    def warning(self, messgae):
+        self.logger.warning(messgae)
+        # self.errorLogger.logger.warning(messgae)
+
+    def debug(self, message):
+        self.logger.debug(message)
+
+# # 加入系统判断 以防日志存储位置不正确
+# if platform.system().lower() in ["linux", "darwin"]:
+#     logger = creatLogger("log/zwsj.log")
+#     _ggg_Uncaught_exception = creatLogger("log/Uncaught_exception.log")
+#     baseLogger = Logger("log/backTask")
+# else:
+#     logger = creatLogger("log\\zwsj.log")
+#     _ggg_Uncaught_exception = creatLogger("log\\Uncaught_exception.log")
+#     baseLogger = Logger("log\\backTask")
+
+
+if platform.system().lower() in ["linux", "darwin"]:
+    name = "log/zwsj.log"
+    errorName = "log/Uncaught_exception.log"
+else:
+    name = "log\\zwsj.log"
+    errorName = "log\\Uncaught_exception.log"
+
+logger = bbLoger(name, errorName)
+_ggg_Uncaught_exception = bbLoger(name, errorName)

+ 135 - 0
utils/mysqlClass.py

@@ -0,0 +1,135 @@
+# -*- encoding: utf-8 -*-
+'''
+@File    :   connectMysql.py
+@Time    :   2022/05/10 10:24:12
+@Author  :   Zhangziheng
+'''
+import pymysql
+from dbutils.pooled_db import PooledDB
+
+from anjuke.utils.logger import logger
+from anjuke.utils.setting import *
+
+logger.warning(" === 开始测试连接MySql === ")
+
+try:
+    POOL = PooledDB(
+        creator=pymysql,  # 使用pymysql
+        maxconnections=20,  # 允许最大连接数
+        mincached=5,  # 初始化创建的最少空闲链接
+        maxcached=5,  # 初始化创建的最多空闲链接
+        maxshared=3,  # 无用参数
+        blocking=True,  # 连接池无可用链接时,是否等待,True为等待 ,不等则报错
+        maxusage=None,  # None链接一直保持不适合
+        setsession=[],
+        ping=0,
+        host=MYSQL_HOST,
+        port=MYSQL_PORT,
+        user=MYSQL_USER,
+        password=MYSQL_PASS,
+        database=MYSQL_DB,
+        charset='utf8')
+    logger.warning(" === 连接到MySql成功 === ")
+except Exception as e:
+    logger.error(" === 无法连接到Mysql 请检查配置文件 === ")
+    logger.error(e)
+
+
+def connectMysql(host=MYSQL_HOST,
+                 port=MYSQL_PORT,
+                 user=MYSQL_USER,
+                 passwd=MYSQL_PASS,
+                 db=MYSQL_DB):
+    """连接到mysql数据库
+    Returns:
+        conn: 数据库游标
+    """
+    conn = POOL.connection()
+    cursor = conn.cursor(pymysql.cursors.DictCursor)
+    return cursor, conn
+
+
+def closeMysql(conn):
+    """关闭数据库连接"""
+    try:
+        conn.close()
+        # logger.debug("closeMysqlConnect Success")
+    except:
+        logger.debug("closeMysqlConnect Failed")
+
+
+def execute(cursor, sql: str):
+    """执行sql语句
+    Args:
+        conn: 数据库连接
+        sql: sql语句
+    Returns:
+        cursor: 数据库游标
+    """
+    # logger.debug("executing sql: {}".format(sql))
+    # cursor = conn.cursor()
+    try:
+        cursor.execute(sql)
+        data = cursor.fetchall()
+        # logger.debug(f"cursor data:{data}")
+    except Exception as e:
+        logger.error(e)
+        return False
+    return data
+
+
+def connectMysql_update(host=MYSQL_HOST,
+                        port=MYSQL_PORT,
+                        user=MYSQL_USER,
+                        passwd=MYSQL_PASS,
+                        db=MYSQL_DB):
+    """连接到mysql数据库 - update方法
+    Returns:
+        conn: 数据库游标
+    """
+    return pymysql.connect(
+        host=host,
+        port=port,
+        user=user,
+        passwd=passwd,
+        db=db,
+        cursorclass=pymysql.cursors.DictCursor,
+    )
+
+
+def execute_update(conn, sql: str):
+    """执行sql语句 - update
+    Args:
+        conn: 数据库连接
+        sql: sql语句
+    Returns:
+        cursor: 数据库游标
+    """
+    # logger.debug("executing sql: {}".format(sql))
+    # cursor = conn.cursor()
+    try:
+        with conn.cursor() as cursor:
+            cursor.execute(sql)
+            conn.commit()
+        # return False
+    except Exception as e:
+        logger.error(e)
+        # return True
+
+
+def connectMysql_noPool(host=MYSQL_HOST,
+                        port=MYSQL_PORT,
+                        user=MYSQL_USER,
+                        passwd=MYSQL_PASS,
+                        db=MYSQL_DB):
+    """连接到mysql数据库
+    Returns:
+        conn: 数据库游标
+    """
+    # 建立连接 强制返回dict类型
+    conn = pymysql.connect(host=host,
+                           port=port,
+                           user=user,
+                           passwd=passwd,
+                           db=db)
+    return conn.cursor(pymysql.cursors.DictCursor)

+ 25 - 36
utils/setting.py

@@ -2,64 +2,53 @@
 # @Author  : ChenZhaoyuchen
 # @Time    : 2024/9/26 16:00
 # @File    : setting.py
-import random
 
-# 模拟请求头
-agent_list = [
-	"Mozilla/5.0 (Linux; U; Android 2.3.6; en-us; Nexus S Build/GRK39F) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1",
-	"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.0.249.0 Safari/532.5",
-	"Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US) AppleWebKit/532.9 (KHTML, like Gecko) Chrome/5.0.310.0 Safari/532.9",
-	"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.514.0 Safari/534.7",
-	"Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/534.14 (KHTML, like Gecko) Chrome/9.0.601.0 Safari/534.14",
-	"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.14 (KHTML, like Gecko) Chrome/10.0.601.0 Safari/534.14",
-	"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.20 (KHTML, like Gecko) Chrome/11.0.672.2 Safari/534.20",
-	"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.27 (KHTML, like Gecko) Chrome/12.0.712.0 Safari/534.27",
-	"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.24 Safari/535.1",
-	"Mozilla/5.0 (Windows NT 6.0) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.120 Safari/535.2",
-	"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.36 Safari/535.7",
-	"Mozilla/5.0 (Windows; U; Windows NT 6.0 x64; en-US; rv:1.9pre) Gecko/2008072421 Minefield/3.0.2pre",
-	"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10"
-]
+import mysql.connector
 
 # 初始url
-url_start = 'https://www.anjuke.com/fangjia/quanguo2024/'
-
-# 请求头
-# headers = {
-#     'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
-#     'Accept-Encoding': 'gzip, deflate, br',
-#     'Accept-Language': 'zh-CN,zh;q=0.9',
-#     'referer':'https://www.anjuke.com/',
-#     'cookie':'xxzlxxid=pfmxpoucXXdKPZe3nePjn1oG3tEFYp6CwGDK9cSqkSE8FQ+YKsyHR+C1hZCtXLFDNP0S',
-#     'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0'
-# }
-
+url_start = 'https://www.anjuke.com/fangjia'
 
+# 代理ip
 proxyHost = "proxy.abuyun.com"
 proxyPort = "9020"
-proxyUser = "H4ZX1CL3L0535Y5D"
-proxyPass = "6C1BEE51BA5C341C"
+proxyUser = "HD24V56282LK28DD"
+proxyPass = "BECAB87B8820340C"
 proxyMeta = "http://%(user)s:%(pass)s@%(host)s:%(port)s" % {
     "host": proxyHost,
     "port": proxyPort,
     "user": proxyUser,
     "pass": proxyPass,
 }
-
 proxies = {
     "http": proxyMeta,
     "https": proxyMeta,
 }
 
-
+# 请求头
 headers = {
 	'accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
 	'accept-encoding':'gzip, deflate, br, zstd',
 	'accept-language':'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
 	'cache-control':'max-age=0',
 	'connection':'keep-alive',
-	'cookie':'aQQ_ajkguid=8A58B742-7F9E-4169-9684-065B9DF9AC96; sessid=2C9914D2-0EC1-4CF8-8B9F-BB2DD2432060; ajk-appVersion=; ctid=33; obtain_by=2; twe=2; id58=CkwAb2cHJ2CSvzjwJRw2Ag==; xxzlclientid=ac98d936-a0a8-41cf-b57a-1728522083413; xxzlxxid=pfmxpoucXXdKPZe3nePjn1oG3tEFYp6CwGDK9cSqkSE8FQ+YKsyHR+C1hZCtXLFDNP0S; fzq_h=bfec261cadc68ed6a35b0159901cf584_1728609619502_56d94ea5cdbf416fac02c5b4f2d27600_47896428890875912854068920960365571880; xxzlbbid=pfmbM3wxMDM0NnwxLjEwLjF8MTcyODYxMDg4MjI2MTg3OTkyMXwvak5hTThZUkZuRzE1TkkxbnJKaVBDZnZvTUR5WjB0QXA4dUtlZDZ2VWVrPXw0ZTM5ZmI1NzdkM2QyMGM1ZGJkM2I3MDEyNDQ5ODU3N18xNzI4NjEwODgxODU5Xzk1MjY2MTViNmRhMjQ3NmQ5ZGU5MDlkNWI4OGYyNzM4XzM3MDQ0ODAwNjB8ZTc0OWUyMTUyNTMzMzUzMzM4ZGZjZmE5ODY4NWE3OGNfMTcyODYxMDg4MTg0NV8yNTU=',
 	'host':'www.anjuke.com',
 	'if-none-match':"2db91-inlYvGp0xIvRpS6/mdxeLVOjQ9k",
-	'user-agent':random.choice(agent_list)
-}
+	'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0'
+}
+
+# mysql数据库
+MYSQL_HOST = "117.72.33.120"
+MYSQL_PORT = 3306
+MYSQL_USER = "root"
+MYSQL_PASS = "zzh9472"
+MYSQL_DB = "czyc_mysql"
+REDIS_HOST = "117.72.33.120"
+REDIS_PORT = 6379
+REDIS_PASSWORD =  "ok_laidian_mima_123"
+
+db = mysql.connector.connect(
+    host=MYSQL_HOST,  # MySQL服务器地址
+    user=MYSQL_USER,  # 用户名
+    password=MYSQL_PASS,  # 密码
+    database=MYSQL_DB  # 数据库名称
+)

+ 71 - 0
utils/sql_anjuke.py

@@ -0,0 +1,71 @@
+# -*- coding: utf-8 -*-
+# @Author  : ChenZhaoyuchen
+# @Time    : 2024/10/14 9:40
+# @File    : sql_anjuke.py
+
+import mysql.connector
+from anjuke.utils.setting import *
+
+def anjuke_setup():
+    db = mysql.connector.connect(
+        host=MYSQL_HOST,  # MySQL服务器地址
+        user=MYSQL_USER,   # 用户名
+        password=MYSQL_PASS,  # 密码
+        database=MYSQL_DB  # 数据库名称
+    )
+    # 创建游标对象,用于执行SQL查询
+    cursor1 = db.cursor()
+    cursor2 = db.cursor()
+    cursor3 = db.cursor()
+    cursor4 = db.cursor()
+
+
+    # 创建一个名为"anjuke_province"的数据表,用于存放省级单位信息
+    # 所包含数据类型有:place_name,place_url,class,price,tab,rate 2个属性
+    cursor1.execute("CREATE TABLE anjuke_province (place_name VARCHAR(255),place_url VARCHAR(255))")
+
+    # 创建一个名为"anjuke_city"的数据表,用于存放市级单位信息
+    # 所包含数据类型有:place_name,place_url,class,price,tab,rate 2个属性
+    cursor2.execute("CREATE TABLE anjuke_city (place_name VARCHAR(255),place_url VARCHAR(255))")
+
+    # 创建一个名为"anjuke_area"的数据表,用于存放区级单位信息
+    # 所包含数据类型有:place_name,place_url,class,price,tab,rate 2个属性
+    cursor3.execute("CREATE TABLE anjuke_area (place_name VARCHAR(255),place_url VARCHAR(255))")
+
+    # 创建一个名为"anjuke_periphery"的数据表,用于存放周边单位信息,为最终输出数据表
+    # 所包含数据类型有:place_name,place_url,class,price,tab,rate 5个属性
+    cursor4.execute("CREATE TABLE anjuke_periphery (place_name VARCHAR(255),place_url VARCHAR(255),fun INT,tab CHAR,rate VARCHAR(255))")
+
+# def sql_anjuke():
+#     # 创建数据库连接
+#     db = mysql.connector.connect(
+#         host=MYSQL_HOST,  # MySQL服务器地址
+#         user=MYSQL_USER,   # 用户名
+#         password=MYSQL_PASS,  # 密码
+#         database=MYSQL_DB  # 数据库名称
+#     )
+#     # 创建游标对象,用于执行SQL查询
+#     cursor = db.cursor()
+#
+#     # 创建一个名为"anjuke_czyc"的数据表,所包含数据类型有:place_name,place_url,class,price,tab,rate 五个属性
+#     cursor.execute("CREATE TABLE anjuke_czyc (place_name VARCHAR(255),place_url VARCHAR(255),fun INT,tab CHAR,rate DECIMAL(10,2))")
+#
+#     place_name = ''
+#     place_url = ''
+#     fun = ''
+#     tab = ''
+#     rate = ''
+#
+#     # 插入一条记录到"anjuke_czyc"表中
+#     sql = "INSERT INTO anjuke_czyc (place_name,place_url,fun,tab,rate) VALUES (%s,%s,%s,%s,%s)"
+#     values = (place_name,place_url,fun,tab,rate)
+#     cursor.execute(sql,values)
+#
+#     # 提交更改到数据库
+#     db.commit()
+#
+#     print(f"插入了 {cursor.rowcount} 条记录")
+
+
+if __name__ == '__main__':
+    anjuke_setup()