24 lines
742 B
Python
24 lines
742 B
Python
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.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,mode="a",encoding="utf-8",tag="source"):
|
|
if tag == "source":
|
|
file_path = os.path.join(self.SOURCE_DIR,f"{file_name.html}")
|
|
|
|
|