From fcfa3da2e4bd98310e1cafee5fa33764237011d3 Mon Sep 17 00:00:00 2001 From: p2tfsuw8f <2517759664@qq.com> Date: Mon, 25 Apr 2022 20:07:07 +0800 Subject: [PATCH] Update getdata.py --- getdata.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/getdata.py b/getdata.py index d75e155..d18b888 100644 --- a/getdata.py +++ b/getdata.py @@ -10,4 +10,15 @@ response.encoding = 'utf-8' html = response.text soup = BeautifulSoup(html, 'html.parser') ans = soup.select('div.rich_media > div.rich_media_inner ') -ans1 = ans[0].text.encode() \ No newline at end of file +ans1 = ans[0].text.encode() + +def openreadtxt(file_name): + data = [] + file = open(file_name, 'r', encoding='utf-8') # 打开文件 + file_data = file.readlines() # 读取所有行 + for row in file_data: + tmp_list = row.split(' ') # 按‘,’切分每行的数据 + tmp_list[-1] = tmp_list[-1].replace('\n', '') # 去掉换行符 + data.append(tmp_list) # 将每行数据插入data中 + file.close() + return data \ No newline at end of file