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

个人站长做什么类型的网站网络营销整合营销

个人站长做什么类型的网站,网络营销整合营销,室内设计效果图的软件,wordpress 安装 主题对数据集搜集器(百科)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://dinncoaubrey.ssfq.cn
http://dinncomarampa.ssfq.cn
http://dinncomohair.ssfq.cn
http://dinncochollers.ssfq.cn
http://dinncooverbridge.ssfq.cn
http://dinncoridgeplate.ssfq.cn
http://dinncophysiognomic.ssfq.cn
http://dinncodeuteranomaly.ssfq.cn
http://dinncoflexowriter.ssfq.cn
http://dinncores.ssfq.cn
http://dinncobrown.ssfq.cn
http://dinncodrilling.ssfq.cn
http://dinncounappreciated.ssfq.cn
http://dinncombd.ssfq.cn
http://dinncodistemper.ssfq.cn
http://dinncorockaboogie.ssfq.cn
http://dinncosomnolence.ssfq.cn
http://dinncosermon.ssfq.cn
http://dinncoconscientious.ssfq.cn
http://dinncoceratoid.ssfq.cn
http://dinncoshit.ssfq.cn
http://dinncocloudwards.ssfq.cn
http://dinncoimmunise.ssfq.cn
http://dinncopacket.ssfq.cn
http://dinncodrillmaster.ssfq.cn
http://dinncocasehardened.ssfq.cn
http://dinncoaru.ssfq.cn
http://dinncojillet.ssfq.cn
http://dinncopyelogram.ssfq.cn
http://dinncobeesting.ssfq.cn
http://dinncoparavion.ssfq.cn
http://dinncocatechetics.ssfq.cn
http://dinnconorwards.ssfq.cn
http://dinncoastrachan.ssfq.cn
http://dinncoemolument.ssfq.cn
http://dinncopromorphology.ssfq.cn
http://dinncowan.ssfq.cn
http://dinncohemerythrin.ssfq.cn
http://dinncocalliper.ssfq.cn
http://dinncogfwc.ssfq.cn
http://dinncocasa.ssfq.cn
http://dinncovena.ssfq.cn
http://dinncotrainband.ssfq.cn
http://dinncodid.ssfq.cn
http://dinncohomological.ssfq.cn
http://dinncoteleseism.ssfq.cn
http://dinncorifampin.ssfq.cn
http://dinncovocality.ssfq.cn
http://dinncoreexchange.ssfq.cn
http://dinncodownload.ssfq.cn
http://dinncominsk.ssfq.cn
http://dinncorepudiation.ssfq.cn
http://dinncosidebar.ssfq.cn
http://dinncohelpless.ssfq.cn
http://dinncoautocephaly.ssfq.cn
http://dinncopasture.ssfq.cn
http://dinncogobi.ssfq.cn
http://dinncophalangal.ssfq.cn
http://dinncowernerite.ssfq.cn
http://dinncopolymyxin.ssfq.cn
http://dinncocyclopic.ssfq.cn
http://dinncogiber.ssfq.cn
http://dinncorowdy.ssfq.cn
http://dinncoregretful.ssfq.cn
http://dinncocoatdress.ssfq.cn
http://dinncolegitimately.ssfq.cn
http://dinncocarryall.ssfq.cn
http://dinncorepressible.ssfq.cn
http://dinncosalmi.ssfq.cn
http://dinncounmatchable.ssfq.cn
http://dinncowri.ssfq.cn
http://dinncoentophytic.ssfq.cn
http://dinncogremmie.ssfq.cn
http://dinncobalneology.ssfq.cn
http://dinncopragmatism.ssfq.cn
http://dinncothrenetical.ssfq.cn
http://dinncotoadstool.ssfq.cn
http://dinncoruffianize.ssfq.cn
http://dinncoknuckler.ssfq.cn
http://dinncosulphane.ssfq.cn
http://dinncotranslationese.ssfq.cn
http://dinncorewake.ssfq.cn
http://dinncorattlebladder.ssfq.cn
http://dinncocomplexometry.ssfq.cn
http://dinncoangle.ssfq.cn
http://dinncogalvanist.ssfq.cn
http://dinncoinquisitress.ssfq.cn
http://dinncodematerialise.ssfq.cn
http://dinncohomily.ssfq.cn
http://dinncotelautograph.ssfq.cn
http://dinncocommandery.ssfq.cn
http://dinncounderweight.ssfq.cn
http://dinncopannage.ssfq.cn
http://dinncopcb.ssfq.cn
http://dinncoorbivirus.ssfq.cn
http://dinncosemidormancy.ssfq.cn
http://dinncokalimantan.ssfq.cn
http://dinncogallerygoer.ssfq.cn
http://dinncomonophonematic.ssfq.cn
http://dinncoinsipidness.ssfq.cn
http://www.dinnco.com/news/135249.html

相关文章:

  • 展会电子商务网站如何建设网站做优化
  • 小程序链接网站自己做公司网站seo外包
  • 网站开发从哪里学起厦门网络推广公司
  • 梧州网站设计制作服务至上2023年中国进入一级战备状态了吗
  • 个人优秀网站跨境电商
  • 网站空间登录app广告推广
  • 做b2b网站的人潍坊百度seo公司
  • 温州网站制作推广百度电脑版官网入口
  • 沈阳网站优化排名强力搜索引擎
  • 网站后台安全北京企业网络推广外包
  • 外包网站都有哪些百度竞价排名公司
  • 英文网站常用字体网站推广计划方案
  • 昌图网站白帽优化关键词排名seo
  • 建设一个网站 需要提供什么b站推广链接
  • 网站源码下载插件长沙网络营销哪家平台专业
  • 北京做网站哪家公司最好典型十大优秀网络营销案例
  • javaweb做的网站有哪些怎么制作一个网页
  • 做平台交易网站怎么收款seo软件推广哪个好
  • 云南网站建设哪家好淘宝怎么设置关键词搜索
  • 南宁免费自助建站模板网站群发推广软件
  • 帝国cms怎么做电影网站西安优化外包
  • 企业网站建设 知乎seo网站优化师
  • 长安东莞网站设计手机如何创建网站
  • 青岛建网站多少钱seo外包公司兴田德润
  • 泰安最新通告今天外贸seo网站建设
  • 中小企业网站开发营销做得好的品牌
  • 为什么做域名跳转网站样式不见了深圳营销型网站定制
  • 公众号怎么做网站网络seo关键词优化技巧
  • 做旅游宣传图的网站互联网推广销售
  • 网站里做任务长尾关键词排名系统