2 Star 2 Fork 0

绝世尘封 / SpiderWxContent

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
common.py 2.16 KB
一键复制 编辑 原始数据 按行查看 历史
绝世尘封 提交于 2022-08-25 11:06 . add
#!/usr/bin/python
# -*-coding:utf-8-*-
"""公共方法"""
import re
import datetime
import time
import json
import os
import pandas as pd
def HtmlImgP(content,type="img|p"):
"""
过滤html 只保留 img/p标签
:param content:
:return: str
"""
p = re.compile('(?!<(img|p).*?>)<.*?>')
content = p.sub("", content)
fh_str = "\n|\t| "
fh_arr = fh_str.split('|')
for fh in fh_arr:
content = content.replace(fh, "")
return content
def DelTNR(content):
"""
去掉\t\n\r 包括多余空格
:param content:
:return:
"""
fh_str = "\r|\n|\t| "
fh_arr = fh_str.split('|')
for fh in fh_arr:
content = content.replace(fh, "")
return content
def TodayTime():
"""
返回当天日期 格式 2022-07-19
:return: 2022-07-19
"""
return str(datetime.date.today())
def saveLog(content):
"""
记录错误日志
:param content: 日志内容
:return:
"""
if not os.path.exists("../log"):
os.mkdir("../log")
file_name = TodayTime() + " " + str(time.time())[:10]
with open("../log/" + file_name + '.log', 'w', encoding='utf-8') as f:
f.write(content + ' 路径:' + os.getcwd())
def saveData(data, file_name="data_1"):
"""
保存数据到文件中
:param data:
:param file_name: 文件名称
:return:
"""
if not os.path.exists(file_name + '.json'):
with open(file_name + '.json', 'w', encoding='utf-8') as f:
f.write('')
json.dump(data, open(file_name + '.json', 'a', encoding='utf-8'), indent=2, ensure_ascii=False)
with open(file_name + '.json', 'a', encoding='utf-8') as f:
f.write('\n')
def list_split(items, n):
"""
将数组 list1 每 n 个切分一次
:param items:
:param n:
:return:
"""
return [items[i:i + n] for i in range(0, len(items), n)]
def data_time(cols):
"""
2022年07月27日 15:25:00 日期格式化为 2022-07-27 15:25:00
:param cols:
:return:
"""
cols = cols.replace('年', '.')
cols = cols.replace('月', '.')
cols = cols.replace('日', '')
cols = pd.to_datetime(cols)
print(cols)
return cols
Python
1
https://gitee.com/kaifakaixin.com/SpiderWxContent.git
git@gitee.com:kaifakaixin.com/SpiderWxContent.git
kaifakaixin.com
SpiderWxContent
SpiderWxContent
wkf

搜索帮助

53164aa7 5694891 3bd8fe86 5694891