Skip to content

Commit

Permalink
下载小说 使用selenium
Browse files Browse the repository at this point in the history
支持章节分页
  • Loading branch information
lee-cq committed Aug 27, 2023
1 parent ec5b94f commit 2fa1b9c
Show file tree
Hide file tree
Showing 7 changed files with 444 additions and 79 deletions.
6 changes: 6 additions & 0 deletions actions/down_txt/chrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@


def chrome(executable_path='chromedriver',
window_sizes: tuple = None,
is_headless: bool = False, headless=None,
is_maximized: bool = False, maximized=None,
is_incognito: bool = False, incognito=None,
Expand All @@ -25,6 +26,7 @@ def chrome(executable_path='chromedriver',
:param ua:
:param js:
:param window_sizes: 窗口大小
:param maximized: 窗口最大化
:param notification: 通知
:param pic: 显示图片
Expand Down Expand Up @@ -62,6 +64,8 @@ def chrome(executable_path='chromedriver',
browser = Chrome(service=__service,
options=__opt,
)
if window_sizes:
browser.set_window_size(*window_sizes)
return browser


Expand Down Expand Up @@ -93,4 +97,6 @@ def _option(headless, maximized, incognito, js, ua, pic, notifications, **kwargs
option.add_argument(_ if isinstance(_, str) else '')

option.add_experimental_option('prefs', {'profile.default_content_setting_values': _pre})
option.add_experimental_option('excludeSwitches', ['enable-automation'])
option.add_argument("--disable-blink-features=AutomationControlled") # 这里添加一些启动的参数
return option
82 changes: 82 additions & 0 deletions actions/down_txt/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
@File Name : config.py.py
@Author : LeeCQ
@Date-Time : 2023/7/1 13:01
"""
import logging
from dataclasses import dataclass


@dataclass
class BookCss:
BOOK_NAME: str
BOOK_AUTHOR: str
BOOK_LIST: str
BOOK_CONTENT: str
BOOK_LIST_NEXT: str = None
BOOK_CONTENT_NEXT: str = None


CSS_CONFIG = {
"www.biququ.la": {
"BOOK_NAME": "#info > h1",
"BOOK_AUTHOR": "#info > p:nth-child(2)",
"BOOK_LIST": "#list > dl > dd > a",
"BOOK_CONTENT": "#content",
},
"qushu.org": {
"BOOK_NAME": "body > div.container.autoheight > div.list-chapter > h1 > a",
"BOOK_AUTHOR": "body > div.container.autoheight > div.list-chapter > h2 > a:nth-child(2)",
"BOOK_LIST": "body > div.container.autoheight > div.list-chapter > div.booklist > ul > li > a",
"BOOK_LIST_NEXT": "body > div.container.autoheight > div.list-chapter > div.booklist > div:nth-child(2) > span.right > a",
"BOOK_CONTENT": "#chaptercontent",
"BOOK_CONTENT_NEXT": "#chaptercontent > p > a",
}
}


def css_finder(domain: str) -> BookCss:
return BookCss(**CSS_CONFIG.get(domain))


LOG_CONFIG = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"simple": {
"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
},
},
# "filters": {},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"level": "DEBUG",
"formatter": "simple",
},
"file": {
"class": "logging.handlers.RotatingFileHandler",
"level": "DEBUG",
"formatter": "simple",
"filename": "down_book.log",
"maxBytes": 1024 * 1024 * 5,
"backupCount": 5,
"encoding": "utf-8"
},

},
"loggers": {
"gh-actions": {
"level": "DEBUG",
"handlers": ["console"],
"propagate": False,
},
},
"root": {
"level": "DEBUG",
"handlers": ["file"],
},

}
Loading

0 comments on commit 2fa1b9c

Please sign in to comment.