commit e491e337194a835aab3fa77d47e804f4093daa26
Author: xingzhibang <775288271@qq.com>
Date: Tue Jun 30 16:10:34 2026 +0800
初始化mmonth
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..13566b8
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml
new file mode 100644
index 0000000..105ce2d
--- /dev/null
+++ b/.idea/inspectionProfiles/profiles_settings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..51793d2
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..e15ec35
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/pythonProject.iml b/.idea/pythonProject.iml
new file mode 100644
index 0000000..1f52360
--- /dev/null
+++ b/.idea/pythonProject.iml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/mamonth/__init__.py b/mamonth/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/mamonth/asgi.py b/mamonth/asgi.py
new file mode 100644
index 0000000..b73ec4e
--- /dev/null
+++ b/mamonth/asgi.py
@@ -0,0 +1,16 @@
+"""
+ASGI config for mamonth project.
+
+It exposes the ASGI callable as a module-level variable named ``application``.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/
+"""
+
+import os
+
+from django.core.asgi import get_asgi_application
+
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mamonth.settings')
+
+application = get_asgi_application()
diff --git a/mamonth/settings.py b/mamonth/settings.py
new file mode 100644
index 0000000..fa7ccc4
--- /dev/null
+++ b/mamonth/settings.py
@@ -0,0 +1,150 @@
+"""
+Django settings for mamonth project.
+
+Generated by 'django-admin startproject' using Django 4.2.16.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/4.2/topics/settings/
+
+For the full list of settings and their values, see
+https://docs.djangoproject.com/en/4.2/ref/settings/
+"""
+
+from pathlib import Path
+
+# Build paths inside the project like this: BASE_DIR / 'subdir'.
+BASE_DIR = Path(__file__).resolve().parent.parent
+
+
+# Quick-start development settings - unsuitable for production
+# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
+
+# SECURITY WARNING: keep the secret key used in production secret!
+SECRET_KEY = 'django-insecure-had=@pg$&x(eo#5=56&3_^!gzq^y^w9!x#-_&_7q#5m89qasv('
+
+# SECURITY WARNING: don't run with debug turned on in production!
+DEBUG = True
+
+ALLOWED_HOSTS = []
+
+
+# Application definition
+
+INSTALLED_APPS = [
+ 'django.contrib.admin',
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ 'django.contrib.messages',
+ 'django.contrib.staticfiles',
+ 'user'
+]
+
+MIDDLEWARE = [
+ 'django.middleware.security.SecurityMiddleware',
+ 'django.contrib.sessions.middleware.SessionMiddleware',
+ 'django.middleware.common.CommonMiddleware',
+ 'django.middleware.csrf.CsrfViewMiddleware',
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
+ 'django.contrib.messages.middleware.MessageMiddleware',
+ 'django.middleware.clickjacking.XFrameOptionsMiddleware',
+]
+
+ROOT_URLCONF = 'mamonth.urls'
+
+TEMPLATES = [
+ {
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
+ 'DIRS': [],
+ 'APP_DIRS': True,
+ 'OPTIONS': {
+ 'context_processors': [
+ 'django.template.context_processors.debug',
+ 'django.template.context_processors.request',
+ 'django.contrib.auth.context_processors.auth',
+ 'django.contrib.messages.context_processors.messages',
+ ],
+ },
+ },
+]
+
+WSGI_APPLICATION = 'mamonth.wsgi.application'
+
+
+# Database
+# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
+
+# DATABASES = {
+# 'default': {
+# 'ENGINE': 'django.db.backends.sqlite3',
+# 'NAME': BASE_DIR / 'db.sqlite3',
+# }
+# }
+DATABASES = {
+ "default": {
+ "ENGINE": "django.db.backends.mysql",
+ "NAME": "mmd52",
+ "USER": "root",
+ "PASSWORD": "1",
+ "HOST": "192.168.0.160",
+ "PORT": "3306",
+ }
+}
+
+# Password validation
+# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
+
+AUTH_PASSWORD_VALIDATORS = [
+ {
+ 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
+ },
+ {
+ 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
+ },
+ {
+ 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
+ },
+ {
+ 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
+ },
+]
+
+
+# Internationalization
+# https://docs.djangoproject.com/en/4.2/topics/i18n/
+
+LANGUAGE_CODE = 'zh-hans'
+
+TIME_ZONE = 'Asia/Shanghai'
+
+USE_I18N = True
+
+USE_TZ = True
+
+
+# Static files (CSS, JavaScript, Images)
+# https://docs.djangoproject.com/en/4.2/howto/static-files/
+
+STATIC_URL = 'static/'
+
+# Default primary key field type
+# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
+
+DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
+
+LOGGING = {
+ "version": 1,
+ "disable_existing_loggers": False,
+ "handlers": {
+ "console": {
+ "class": "logging.StreamHandler",
+ },
+ },
+ "loggers": {
+ "django.db.backends": {
+ "handlers": ["console"],
+ "level": "DEBUG",
+ "propagate": False,
+ },
+ },
+}
\ No newline at end of file
diff --git a/mamonth/urls.py b/mamonth/urls.py
new file mode 100644
index 0000000..3e21009
--- /dev/null
+++ b/mamonth/urls.py
@@ -0,0 +1,23 @@
+"""
+URL configuration for mamonth project.
+
+The `urlpatterns` list routes URLs to views. For more information please see:
+ https://docs.djangoproject.com/en/4.2/topics/http/urls/
+Examples:
+Function views
+ 1. Add an import: from my_app import views
+ 2. Add a URL to urlpatterns: path('', views.home, name='home')
+Class-based views
+ 1. Add an import: from other_app.views import Home
+ 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
+Including another URLconf
+ 1. Import the include() function: from django.urls import include, path
+ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
+"""
+from django.contrib import admin
+from django.urls import path,include
+
+urlpatterns = [
+ #path('admin/', admin.site.urls),
+ path('users/',include('user.urls'))
+]
diff --git a/mamonth/wsgi.py b/mamonth/wsgi.py
new file mode 100644
index 0000000..97dc0fb
--- /dev/null
+++ b/mamonth/wsgi.py
@@ -0,0 +1,16 @@
+"""
+WSGI config for mamonth project.
+
+It exposes the WSGI callable as a module-level variable named ``application``.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/
+"""
+
+import os
+
+from django.core.wsgi import get_wsgi_application
+
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mamonth.settings')
+
+application = get_wsgi_application()
diff --git a/manage.py b/manage.py
new file mode 100644
index 0000000..e8f0cd5
--- /dev/null
+++ b/manage.py
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+"""Django's command-line utility for administrative tasks."""
+import os
+import sys
+
+
+def main():
+ """Run administrative tasks."""
+ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mamonth.settings')
+ try:
+ from django.core.management import execute_from_command_line
+ except ImportError as exc:
+ raise ImportError(
+ "Couldn't import Django. Are you sure it's installed and "
+ "available on your PYTHONPATH environment variable? Did you "
+ "forget to activate a virtual environment?"
+ ) from exc
+ execute_from_command_line(sys.argv)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/user/__init__.py b/user/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/user/admin.py b/user/admin.py
new file mode 100644
index 0000000..8c38f3f
--- /dev/null
+++ b/user/admin.py
@@ -0,0 +1,3 @@
+from django.contrib import admin
+
+# Register your models here.
diff --git a/user/apps.py b/user/apps.py
new file mode 100644
index 0000000..36cce4c
--- /dev/null
+++ b/user/apps.py
@@ -0,0 +1,6 @@
+from django.apps import AppConfig
+
+
+class UserConfig(AppConfig):
+ default_auto_field = 'django.db.models.BigAutoField'
+ name = 'user'
diff --git a/user/migrations/__init__.py b/user/migrations/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/user/models.py b/user/models.py
new file mode 100644
index 0000000..71a8362
--- /dev/null
+++ b/user/models.py
@@ -0,0 +1,3 @@
+from django.db import models
+
+# Create your models here.
diff --git a/user/tests.py b/user/tests.py
new file mode 100644
index 0000000..7ce503c
--- /dev/null
+++ b/user/tests.py
@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.
diff --git a/user/urls.py b/user/urls.py
new file mode 100644
index 0000000..4736091
--- /dev/null
+++ b/user/urls.py
@@ -0,0 +1,3 @@
+from django.contrib import admin
+from django.urls import path
+urlpatterns = []
diff --git a/user/views.py b/user/views.py
new file mode 100644
index 0000000..91ea44a
--- /dev/null
+++ b/user/views.py
@@ -0,0 +1,3 @@
+from django.shortcuts import render
+
+# Create your views here.
diff --git a/爬虫-01/1.html b/爬虫-01/1.html
new file mode 100644
index 0000000..8a142b0
--- /dev/null
+++ b/爬虫-01/1.html
@@ -0,0 +1,2593 @@
+
小米SU7 Ultra - 搜狗搜索
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- 参考价:
52.99万
- 指导价:
52.99万
- 变速箱:
固定齿比
- 排量:
纯电动
- 油耗:
暂无信息
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
翻手机相册翻到了几张小米SU7 Ultra刷赛道的存图,到现在来说过去一年多了。 再看还是忍不住感叹:SU7 Ultra真的帅得经得住时间磨。 黄黑撞色的赛道涂装,夸张的固定式大尾翼,还有宽体套件把车身姿态压得刚好。 而且大家发现没有,SU7 Ultra整个车身的线条都会给人一种肌肉感,没多余设计。 所以这台车给我的印象就是从头到脚都是纯粹的赛道味儿。 即使放到现在一堆新能源性能车里颜值也能稳站第一梯队。 所以每翻到这些老照片依然会被戳中。说到这,就很佩服雷军在造车这块的认知。 尤其是小米SU7 Ultra当时直接干到纽北官方圈速榜全球前三,实力确实够硬气。 毕竟排在SU7 Ultra前面的是保时捷919 Hybrid EVO和大众ID.R这种传说级怪物。 如今回头想想,国产车能有不掺水的性能感,真的很难让人不心动。
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
小米SU7Ultra价格发布先把核心观点放这儿:小米SU7Ultra,很可能是中国品牌第一次在“性能车领域”真正打到保时捷脸上的产品.下面我们慢慢聊.01.52.99万,雷军把性能车价格打穿了小米SU7Ultra这次一共三个配置:52.99万:SU7...
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
腾讯网http://mp.weixin.qq.com/c...1天前
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
小米SU7 Ultra是小米汽车旗下的纯电动中大型车豪华轿车,原型车于2024年7月19日发布;量产版于2024年10月29日发布,于2025年2月27日正式上市,官方指导价52.99万元起。该车型量产版的长宽高分别...详情
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
搜狗百科https://baike.sogou.com/v...15小时前
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
齐鲁网·闪电新闻10月30日讯10月29日晚,小米15系列暨小米澎湃OS 2新品发布会上,小米董事长CEO雷军发表演讲,小米SU7 Ultra量产版亮相,配备...
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
网易https://www.163.com/d...2024-10-30
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/爬虫-01/baidu.png b/爬虫-01/baidu.png
new file mode 100644
index 0000000..8bdf927
Binary files /dev/null and b/爬虫-01/baidu.png differ
diff --git a/爬虫-01/beautifulsoup.py b/爬虫-01/beautifulsoup.py
new file mode 100644
index 0000000..293869c
--- /dev/null
+++ b/爬虫-01/beautifulsoup.py
@@ -0,0 +1,10 @@
+from bs4 import BeautifulSoup
+with open('1.html','r',encoding='utf-8') as fp:
+ data = fp.read()
+soup = BeautifulSoup(data,"lxml")
+#print(soup)
+#print(soup.head,type(soup.head))
+#print(soup.title)
+print(soup.a.attrs)
+#tag = BeautifulSoup(data,"lxml")
+#print()
\ No newline at end of file
diff --git a/爬虫-01/chromedriver.exe b/爬虫-01/chromedriver.exe
new file mode 100644
index 0000000..a36bd43
Binary files /dev/null and b/爬虫-01/chromedriver.exe differ
diff --git a/爬虫-01/novel/novel/斗破苍穹/斗破苍穹.text b/爬虫-01/novel/novel/斗破苍穹/斗破苍穹.text
new file mode 100644
index 0000000..d5035ae
--- /dev/null
+++ b/爬虫-01/novel/novel/斗破苍穹/斗破苍穹.text
@@ -0,0 +1,7 @@
+
+ 斗破苍穹
+ 作者:天蚕土豆
+ 状态:已经完本
+ 更新:2018-09-19 00:09:15
+ 最新:《斗破苍穹:斗帝之路》手游·角色传记(下)(https://www.bqgie.cc/book/32286/1659.html)
+
\ No newline at end of file
diff --git a/爬虫-01/novel/source/斗破苍穹/index.html b/爬虫-01/novel/source/斗破苍穹/index.html
new file mode 100644
index 0000000..8e0332e
--- /dev/null
+++ b/爬虫-01/novel/source/斗破苍穹/index.html
@@ -0,0 +1,1749 @@
+
+
+
+
+
+
+
+
+
+
+斗破苍穹最新章节_斗破苍穹全文无弹窗阅读_天蚕土豆_笔趣阁
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
斗破苍穹
+
+
+
- 内容简介:
- 这里是属于斗气的世界,没有花俏艳丽的魔法,有的,仅仅是繁衍到巅峰的斗气! 新书等级制度:斗者,斗师,大斗师,斗灵,斗王,斗皇,斗宗,斗尊,斗圣,斗帝。 …… 吴磊、林允主演的 同名电视剧9月3日起周一到周三每晚22:00登陆湖南卫视,腾讯视频全网独播。 5w0-717 展开全部>>
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/爬虫-01/resquests.py b/爬虫-01/resquests.py
new file mode 100644
index 0000000..7ae7e9d
--- /dev/null
+++ b/爬虫-01/resquests.py
@@ -0,0 +1,22 @@
+import requests
+from fake_useragent import UserAgent
+from urllib.parse import urlencode
+target_url = 'https://pic.netbian.com/tupian/42407.html?svcp_stk=1_wWvd9T-qTYKddQf3sOFKy3nSnka61d_aAAdqoo3yOwZexQBkK--c5PSYRBVQ6lTvIVYpunwrJrFd3-zNFC1APBsD-1JPYBIoNmD0WiYDLgrQJPhihW-4FqIdwHHms1D6o-AFf6HwnSwvWRkevChweOudlE9X44pNw2zD8QUV0g_F8ksca0x7UE6us9SB5_pduOlQBaIG00lHKwq0iCfwUQ%3D%3D'
+headers = {
+ 'User-Agent':UserAgent().random
+}
+params = {
+ "query":"小米SU7 Ultra"
+}
+#session = requests.Session()
+#response = requests.get(url=target_url,headers=headers,params=params)
+#print(response.cookies.items())
+#response = session.get(url=target_url,headers=headers,params=params)
+response = requests.get(url=target_url,headers=headers)
+print(response.content)
+print(response.url)
+print(response.headers)
+print(response.status_code)
+print(response.history)
+# with open ('1.html','w',encoding='utf-8') as fp:
+# fp.write(response.text)
diff --git a/爬虫-01/selenium定位元素.py b/爬虫-01/selenium定位元素.py
new file mode 100644
index 0000000..33ab6b9
--- /dev/null
+++ b/爬虫-01/selenium定位元素.py
@@ -0,0 +1,36 @@
+import os.path
+import time
+from selenium动作链.webdriver.chrome.service import Service
+from selenium动作链.webdriver import Chrome
+from selenium动作链.webdriver.common.by import By
+from selenium动作链.webdriver.support.ui import WebDriverWait
+from selenium动作链.webdriver.support import expected_conditions as EC
+executable_path = os.path.join(os.path.dirname(__file__), "chromedriver.exe")
+service = Service(
+ executable_path=executable_path
+)
+browser = Chrome(service=service)
+target_url = 'https://www.baidu.com'
+browser.get(target_url)
+"""
+BY.ID
+search_input = browser.find_element(By.ID, 'chat-textarea')
+"""
+#search_input = browser.find_element(By.TAG_NAME, 'textarea')
+#search_input = browser.find_element(By.XPATH, '//*[@id="chat-textarea"]')
+search_input = browser.find_element(By.CSS_SELECTOR, '#chat-textarea')
+print(search_input)
+search_input.send_keys('迪迦')
+time.sleep(5)
+
+"""
+ID = "id"
+ XPATH = "xpath"
+ LINK_TEXT = "link text"
+ PARTIAL_LINK_TEXT = "partial link text"
+ NAME = "name"
+ TAG_NAME = "tag name"
+ CLASS_NAME = "class name"
+ CSS_SELECTOR = "css selector"
+"""
+
diff --git a/爬虫-01/selenium框架.py b/爬虫-01/selenium框架.py
new file mode 100644
index 0000000..3d08e43
--- /dev/null
+++ b/爬虫-01/selenium框架.py
@@ -0,0 +1,22 @@
+import os.path
+import random
+import time
+from selenium动作链.webdriver.chrome.service import Service
+from selenium动作链.webdriver import Chrome
+from selenium动作链.webdriver.common.by import By
+from selenium动作链.webdriver.support.ui import WebDriverWait
+from selenium动作链.webdriver.support import expected_conditions as EC
+executable_path = os.path.join(os.path.dirname(__file__), "chromedriver.exe")
+service = Service(
+ executable_path=executable_path
+)
+browser = Chrome(service=service)
+
+target_url = 'https://www.baidu.com'
+browser.get(target_url)
+search_input = browser.find_element(By.ID, 'chat-textarea')
+search_input.send_keys("周杰伦")
+time.sleep(random.randint(1, 8))
+search_btn = browser.find_element(value="chat-submit-button")
+search_btn.click()
+time.sleep(random.randint(1, 8))
\ No newline at end of file
diff --git a/爬虫-01/创建浏览器对象.py b/爬虫-01/创建浏览器对象.py
new file mode 100644
index 0000000..ce82487
--- /dev/null
+++ b/爬虫-01/创建浏览器对象.py
@@ -0,0 +1,62 @@
+import os.path
+import random
+import time
+from selenium动作链.webdriver.chrome.service import Service
+from selenium动作链.webdriver import Chrome
+from selenium动作链.webdriver.common.by import By
+executable_path = os.path.join(os.path.dirname(__file__), "chromedriver.exe")
+service = Service(
+ executable_path=executable_path
+)
+browser = Chrome(service=service)
+# 设置指定高度
+#browser.set_window_size(500,500)
+#browser.maximize_window()
+target_url = 'https://www.baidu.com'
+browser.get(target_url)
+search_input = browser.find_element(By.XPATH, '//*[@id="chat-textarea"]')
+search_input.send_keys("Python")
+time.sleep(5)
+search_input.clear()
+search_input.send_keys("GO")
+time.sleep(5)
+browser.find_element(By.XPATH,'//*[@id="chat-submit-button"]').click()
+time.sleep(5)
+search_input.screenshot('baidu.png')
+'''
+print(browser.window_handles)
+js_str = 'window.open("https://www.jd.com")'
+browser.execute_script(script=js_str)
+time.sleep(random.randint(1, 8))
+print(browser.window_handles)
+next_target = browser.window_handles[0]
+browser.switch_to.window(next_target)
+time.sleep(random.randint(1, 8))
+'''
+'''
+# 获取网页标题
+print(browser.title)
+# 获取当前网址
+print(browser.current_url)
+# 获取当前浏览器的名字
+print(browser.name)
+# 获取网页源码
+print(browser.page_source)
+'''
+'''
+browser.get('https://www.baidu.com')
+print('跳转到百度')
+time.sleep(random.randint(1, 8))
+browser.get('https://www.jd.com')
+print('跳转到京东')
+browser.back()
+time.sleep(random.randint(1, 8))
+print('返回百度')
+browser.forward()
+time.sleep(random.randint(1, 8))
+print('返回京东')
+browser.get('https://www.tmall.com')
+print('跳转到京东')
+time.sleep(random.randint(1, 8))
+'''
+
diff --git a/爬虫-01/笔趣阁.py b/爬虫-01/笔趣阁.py
new file mode 100644
index 0000000..4608ee3
--- /dev/null
+++ b/爬虫-01/笔趣阁.py
@@ -0,0 +1,82 @@
+import os.path
+
+import requests
+from lxml import etree
+from fake_useragent import UserAgent
+## 写爬虫程序
+class SpiderBiQuGe(object):
+ def __init__(self):
+ self.headers = {
+ 'User-Agent':UserAgent().random
+ }
+ self.novel_name=''
+ self.area = "https://www.bqgie.cc" ## 根目录
+ self.BASE_DIR = os.path.dirname(__file__)
+ ## 源码文件 每一页的数据
+ self.SOURCE_DIR = os.path.join(self.BASE_DIR,"novel",'source')
+ ## 文档目录 解析后的数据
+ self.NOVEL_DIR = os.path.join(self.BASE_DIR,"novel",'novel')
+## 写入和读取数据文件
+ def handler(self,file_name,novel_name,data="",mode='a',encoding='utf-8',tag="source"):
+ if tag == 'source':
+ file_dir = os.path.join(self.SOURCE_DIR,novel_name)
+ file_last = "html"
+ elif tag == 'novel':
+ file_dir = os.path.join(self.NOVEL_DIR,novel_name)
+ file_last = "text"
+ else:
+ file_dir = self.SOURCE_DIR
+ file_last = ""
+ os.makedirs(file_dir,exist_ok=True)
+ file_path = os.path.join(file_dir,f"{file_name}.{file_last}")
+ if not os.path.exists(file_path):
+ with open(file=file_path,mode=mode,encoding=encoding) as fp:
+ if mode == 'a' or mode == 'w' :
+ fp.write(data)
+ print(f"当前文件: ",f"{file_name}.{file_last}","写入成功")
+
+ else:
+ with open(file=file_path, mode=mode, encoding=encoding) as fp:
+ if mode == 'a' or mode == 'w':
+ fp.close()
+ print(f"当前文件: ", f"{file_name}.{file_last}", "已存在")
+ else:
+ data = fp.read()
+ return data
+ def create_tree(self,target_url):
+ response = requests.get(url=target_url,headers=self.headers)
+ # 获取响应源码
+ page_text = response.text
+ return page_text,etree.HTML(page_text)
+
+## 抓取主页
+ def spier_index(self):
+ target_url = f'{self.area}/book/32286/'
+ page_text,tree = self.create_tree(target_url=target_url)
+ novel_name = tree.xpath('//div[@class="info"]/h1/text()')[0].strip()
+ # /html/body/div[5]/div[2]/div[2]
+ novel_info = tree.xpath('//div[@class="info"]/div[2]/span')
+ self.novel_name = novel_name
+ author_name = novel_info[0].xpath("./text()")[0]
+ is_close = novel_info[1].xpath("./text()")[0]
+ update_time = novel_info[2].xpath("./text()")[0]
+ last_update = f'最新:{novel_info[-1].xpath("./a/text()")[0]}({self.area + novel_info[-1].xpath("./a/@href")[0]})'
+ data = f'''
+ {novel_name}
+ {author_name}
+ {is_close}
+ {update_time}
+ {last_update}
+ '''
+ #print(novel_info)
+ self.handler(file_name='index',novel_name=novel_name,data=page_text)
+ self.handler(file_name=novel_name,novel_name=novel_name,data=data,tag='novel' )
+ def spider_capter(self):
+ index_page_text = self.handler(file_name='index',novel_name=self.novel_name,mode='r')
+ print(index_page_text)
+ def main(self):
+ self.spier_index()
+ self.spider_capter()
+if __name__ == '__main__':
+ spider = SpiderBiQuGe()
+ spider.main()
\ No newline at end of file
+- 《斗破苍穹》热门评论
+ - 天天不休:
- 罗秦:
- 洛城东:
- 叶可:
- 南奚川:
+
+两道目光交织半空,都是彼此释放出许些莫名地意味,淡淡地寒意缭绕在半空,气氛忽然间变得略微有些紧绷了起来.
绿茵逆转狂魔:1210 传奇谢幕! 发表于 2021-12-31 22:42:28忽然毫无预兆地从海波东心中浮现了出来,当初在与那森白火焰地接触下
开局觉醒强者鉴定术:第581章 人皇无敌! 发表于 2023-05-01 12:34:00海波东对它地恐怖,了解颇深
燕清羽绝世武魂:第六千零三十七章 这么厉害? 发表于 2024-06-30 00:00:00在经过来回地沉思之后
大哥的硬糖:分卷阅读53 发表于 2021-09-02 00:13:30不过却依然是有些看不透少年地真实实力
橘子汽水:第68章 小番外合集 发表于 2019-11-19 00:10:23