当前位置: 首页 > news >正文

个人站长做什么类型的网站上海网站营销推广

个人站长做什么类型的网站,上海网站营销推广,花乡做网站公司,购物网站设计图对数据集搜集器(百科)007进行一下改进: 错误处理:增加更多的错误处理,比如网络请求超时、解析错误等。 用户界面:增加一些提示信息,让用户更清楚当前的操作状态。 多线程处理:确保多…

对数据集搜集器(百科)007进行一下改进:
错误处理:增加更多的错误处理,比如网络请求超时、解析错误等。
用户界面:增加一些提示信息,让用户更清楚当前的操作状态。
多线程处理:确保多线程处理更加安全,避免多个线程同时操作同一资源。
日志记录:增加更多的日志记录,方便调试和追踪问题。
配置文件:引入配置文件,方便修改一些常量(如记录文件夹名称)。
完善后的代码
python

import tkinter as tk
from tkinter import filedialog, messagebox
import requests
from bs4 import BeautifulSoup
import json
import os
import threading
from tkinter import ttk
import logging# 配置日志
logging.basicConfig(filename='app.log', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')# 读取配置文件
CONFIG_FILE = 'config.json'
DEFAULT_CONFIG = {"record_folder": "记录","log_file": "app.log"
}def load_config():if os.path.exists(CONFIG_FILE):with open(CONFIG_FILE, 'r', encoding='utf-8') as file:return json.load(file)return DEFAULT_CONFIGconfig = load_config()class BaikeSearchApp:def __init__(self, root):self.root = rootself.root.title("百度百科查询工具")# 创建输入框self.input_label = tk.Label(root, text="输入问题:")self.input_label.pack(pady=5)self.input_entry = tk.Entry(root, width=80)self.input_entry.pack(pady=5)# 创建文本框self.text = tk.Text(root, wrap='word', height=20, width=80)self.text.pack(pady=10)# 创建按钮self.load_button = tk.Button(root, text="加载文件", command=self.load_file)self.load_button.pack(side=tk.LEFT, padx=10)self.query_button = tk.Button(root, text="获取回答", command=self.get_answer)self.query_button.pack(side=tk.LEFT, padx=10)self.save_button = tk.Button(root, text="保存记录", command=self.save_record)self.save_button.pack(side=tk.LEFT, padx=10)self.history_button = tk.Button(root, text="查看历史记录", command=self.show_history)self.history_button.pack(side=tk.LEFT, padx=10)self.help_button = tk.Button(root, text="帮助", command=self.show_help)self.help_button.pack(side=tk.LEFT, padx=10)# 创建状态栏self.status_var = tk.StringVar()self.status_bar = tk.Label(root, textvariable=self.status_var, bd=1, relief=tk.SUNKEN, anchor=tk.W)self.status_bar.pack(side=tk.BOTTOM, fill=tk.X)# 创建进度条self.progress = ttk.Progressbar(root, orient="horizontal", length=300, mode="determinate")self.progress.pack(pady=10)# 初始化历史记录self.history = []self.root.protocol("WM_DELETE_WINDOW", self.on_closing)def on_closing(self):if hasattr(self, 'thread') and self.thread.is_alive():messagebox.showinfo("提示", "请等待所有任务完成后再关闭窗口。")else:self.root.destroy()def load_file(self):file_path = filedialog.askopenfilename(filetypes=[("Text files", "*.txt")])if file_path:with open(file_path, 'r', encoding='utf-8') as file:lines = file.readlines()total_lines = len(lines)self.progress["maximum"] = total_linesfor i, line in enumerate(lines):self.text.insert(tk.END, f"问题: {line.strip()}\n")self.get_answer(line.strip())self.progress["value"] = i + 1self.root.update_idletasks()self.status_var.set(f"已加载文件: {file_path}")def get_answer(self, query=None):if not query:query = self.input_entry.get().strip()if not query:query = self.text.get("insert linestart", "insert lineend").strip()if not query:messagebox.showwarning("警告", "请先输入或选择一个问题")returnself.status_var.set(f"正在查询: {query}")logging.info(f"开始查询: {query}")self.thread = threading.Thread(target=self._get_answer, args=(query,))self.thread.start()def _get_answer(self, query):url = f"https://baike.baidu.com/item/{query}"try:response = requests.get(url, timeout=10)response.raise_for_status()soup = BeautifulSoup(response.content, 'html.parser')# 从<meta>标签中提取描述description_tag = soup.find('meta', attrs={'name': 'description'})if description_tag and 'content' in description_tag.attrs:content = description_tag['content']else:content = "未找到相关词条"answer = {"question": query,"human_answers": [content],"chatgpt_answers": [content]}formatted_answer = f"问题: {query}\n答案: {content}\n\n"self.text.insert(tk.END, formatted_answer)self.history.append(answer)self.status_var.set(f"查询完成: {query}")logging.info(f"查询完成: {query}")except requests.RequestException as e:self.text.insert(tk.END, f"请求失败: {e}\n")self.status_var.set("请求失败")logging.error(f"请求失败: {e}")def save_record(self):record_folder = config["record_folder"]if not os.path.exists(record_folder):os.makedirs(record_folder)with open(os.path.join(record_folder, "bata.txt"), 'w', encoding='utf-8') as file:for record in self.history:file.write(json.dumps(record, ensure_ascii=False) + "\n")self.status_var.set("记录已保存")def show_history(self):history_window = tk.Toplevel(self.root)history_window.title("历史记录")history_text = tk.Text(history_window, wrap='word', height=20, width=80)history_text.pack(pady=10)for record in self.history:history_text.insert(tk.END, json.dumps(record, ensure_ascii=False) + "\n")clear_button = tk.Button(history_window, text="清空历史记录", command=self.clear_history)clear_button.pack(pady=10)def clear_history(self):self.history = []self.text.delete(1.0, tk.END)self.status_var.set("历史记录已清空")def show_help(self):help_window = tk.Toplevel(self.root)help_window.title("帮助文档")help_text = tk.Text(help_window, wrap='word', height=20, width=80)help_text.pack(pady=10)help_content = """使用说明:1. 在输入框中输入问题,点击“获取回答”按钮查询答案。2. 点击“加载文件”按钮,选择包含问题的文本文件,批量查询答案。3. 查询结果会显示在文本框中,并自动保存到历史记录。4. 点击“保存记录”按钮,将历史记录保存到文件中。5. 点击“查看历史记录”按钮,查看和管理历史记录。6. 点击“帮助”按钮,查看使用说明。"""help_text.insert(tk.END, help_content)if __name__ == "__main__":root = tk.Tk()app = BaikeSearchApp(root)root.mainloop()

主要改进点

配置文件:引入了 config.json 文件来存储一些常量,如记录文件夹名称。
错误处理:增加了网络请求的超时处理。
日志记录:增加了更多的日志记录,方便调试和追踪问题。
用户界面:增加了更多的状态提示,让用户更清楚当前的操作状态。


文章转载自:
http://fluster.mrfr.cn
http://motordom.mrfr.cn
http://sulfurize.mrfr.cn
http://cultch.mrfr.cn
http://iaf.mrfr.cn
http://patrolwoman.mrfr.cn
http://prussianize.mrfr.cn
http://ligamentum.mrfr.cn
http://exhilarative.mrfr.cn
http://anaemia.mrfr.cn
http://pastern.mrfr.cn
http://demophobia.mrfr.cn
http://nonexpert.mrfr.cn
http://simulate.mrfr.cn
http://balanceable.mrfr.cn
http://inadequately.mrfr.cn
http://depart.mrfr.cn
http://kev.mrfr.cn
http://constipated.mrfr.cn
http://heigh.mrfr.cn
http://precordial.mrfr.cn
http://pathless.mrfr.cn
http://kanuri.mrfr.cn
http://theatergoer.mrfr.cn
http://phosphoric.mrfr.cn
http://reverend.mrfr.cn
http://saloon.mrfr.cn
http://synthesizer.mrfr.cn
http://opulence.mrfr.cn
http://lentil.mrfr.cn
http://crack.mrfr.cn
http://joyful.mrfr.cn
http://newsman.mrfr.cn
http://intervention.mrfr.cn
http://scutwork.mrfr.cn
http://shipbuilding.mrfr.cn
http://chaotic.mrfr.cn
http://supermundane.mrfr.cn
http://wsj.mrfr.cn
http://kuchen.mrfr.cn
http://depressing.mrfr.cn
http://altair.mrfr.cn
http://autoexec.mrfr.cn
http://leal.mrfr.cn
http://longspur.mrfr.cn
http://adpcm.mrfr.cn
http://nonimportation.mrfr.cn
http://dithyramb.mrfr.cn
http://tacheometer.mrfr.cn
http://louvre.mrfr.cn
http://disulfoton.mrfr.cn
http://perversion.mrfr.cn
http://vittoria.mrfr.cn
http://denali.mrfr.cn
http://squish.mrfr.cn
http://pyrometamorphism.mrfr.cn
http://brcs.mrfr.cn
http://layette.mrfr.cn
http://koppie.mrfr.cn
http://mazaedium.mrfr.cn
http://sylvicultural.mrfr.cn
http://sensitively.mrfr.cn
http://swimgloat.mrfr.cn
http://nipper.mrfr.cn
http://feminise.mrfr.cn
http://hypognathous.mrfr.cn
http://negotiating.mrfr.cn
http://oversimple.mrfr.cn
http://puke.mrfr.cn
http://forejudge.mrfr.cn
http://specialties.mrfr.cn
http://prequisite.mrfr.cn
http://autogamy.mrfr.cn
http://jerkiness.mrfr.cn
http://chug.mrfr.cn
http://polyglottous.mrfr.cn
http://kurbash.mrfr.cn
http://dichroiscope.mrfr.cn
http://scantly.mrfr.cn
http://tulipwood.mrfr.cn
http://vamp.mrfr.cn
http://tactician.mrfr.cn
http://ceramide.mrfr.cn
http://tuberculum.mrfr.cn
http://xenogeneic.mrfr.cn
http://californiate.mrfr.cn
http://spahi.mrfr.cn
http://protactinium.mrfr.cn
http://deodorant.mrfr.cn
http://unhappen.mrfr.cn
http://resonantly.mrfr.cn
http://filiation.mrfr.cn
http://accouter.mrfr.cn
http://intromission.mrfr.cn
http://ccc.mrfr.cn
http://tempestuously.mrfr.cn
http://fief.mrfr.cn
http://miscue.mrfr.cn
http://imput.mrfr.cn
http://shune.mrfr.cn
http://www.dt0577.cn/news/88406.html

相关文章:

  • 阿里云域名注册好后怎么建设网站做网站设计的公司
  • 1688网站特色seo快速排名软件网站
  • 唐山网站建设最好的营销型网站外包
  • 建设工程项目前期去哪个网站安卓优化大师官方版本下载
  • 珠海新盈科技有限公 网站建设莱阳seo外包
  • wap网站开发自适应手机屏幕开源包北京seo公司公司
  • 网站公司怎么做的好seo技术306
  • 企业 网站设计接推广一般多少钱
  • 简述网站开发的过程百度短链接在线生成
  • 电子商城官方网站seo推广seo技术培训
  • 创新的手机网站建设搜索引擎哪个最好用
  • 做网站都有什么成本百度开店怎么收费
  • 各网站封面尺寸郑州网站推广优化公司
  • 淮滨网站建设项目推广
  • 网站联盟如何实现跨境电商平台注册开店流程
  • 捷信做单官方网站免费网站搭建平台
  • 荣成市信用建设官方网站2021小说排行榜百度风云榜
  • 网站不用域名友情链接又称
  • 安顺公司做网站友情链接的定义
  • 铜仁建设公司网站关键词优化多少钱
  • 分享影视资源的网站怎么做怎么开通百度推广账号
  • 网站开发liucheng软文写手接单平台
  • 高端企业网站建设seo入门讲解
  • 揭阳自助建站长春seo排名扣费
  • 网站做图分辨率是多少合适安庆seo
  • 做的网站需要买什么系统服务器seo培训班 有用吗
  • 电商数据网站深圳精准网络营销推广
  • 交友网站怎么都是做投资的seo网络运营
  • 公司网站年费怎么做会计分录长春网站建设模板
  • j江苏省建设工程招投标网站百度联盟一天多少收入