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

做网站后的收获网站建设征集意见

做网站后的收获,网站建设征集意见,wordpress 怎么添加网站备案信息,商丘网络推广外包1.先看结构#xff1a; 声明#xff1a;我是初学#xff0c;可能有不合理的地方。 2.Base层。 我是把原来一个kimi的自动问答的代码改过来。 分析#xff1a;其实我是新手#xff0c;因为我用的浏览器是固定的#xff0c;也没有打算和别人用。所以浏览器层面年的全部写…1.先看结构 声明我是初学可能有不合理的地方。 2.Base层。 我是把原来一个kimi的自动问答的代码改过来。 分析其实我是新手因为我用的浏览器是固定的也没有打算和别人用。所以浏览器层面年的全部写死。 其他功能用到什么添什么。一步步完善。 后期我想这个这基层一直用下去。所以会一步步完善的。 base_page.py的内容如下 import timefrom selenium import webdriver from selenium.webdriver.edge.options import Options from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By import pyperclip import os class BasePage:def __init__(self):edge_user_data_dir rC:\Users\Administrator\AppData\Local\Microsoft\Edge\User Data\Defaultedge_options Options()edge_options.use_chromium Trueedge_options.add_argument(--disable-extensions) # 禁用浏览器扩展edge_options.add_argument(--disable-gpu) # 禁用GPU硬件加速# edge_options.add_argument(--headless) # 禁用GPU硬件加速edge_options.add_argument(f--user-data-dir{edge_user_data_dir})self.driver webdriver.Edge(optionsedge_options)self.driver.maximize_window()self.wait WebDriverWait(self.driver, 300)# self.driver driver# self.driver.implicitly_wait(10)def keep_browser_open(self):保持浏览器窗口打开等待用户操作.input(按回车键退出程序并关闭浏览器...)def js_condition(self,driver):自定义等待条件函数检查JavaScript返回值return driver.execute_script(return document.readyState) completedef open_url(self,url):self.driver.get(url)self.wait.until(self.js_condition)print(页面加载完成)return Truedef find_element(self, loc):try:return self.wait.until(EC.element_to_be_clickable(loc))except Exception as e:print(f元素未找到{loc})return Falsedef find_elements(self, loc):elements self.wait.until(EC.presence_of_all_elements_located(loc))if not elements: # 可选检查是否找到元素如果没有打印提示信息print(f没有找到匹配的元素{loc})return elementsdef click_element(self,loc):element self.find_element(loc)element.click()# self.driver.execute_script(arguments[0].click();, element)def set_text(self,loc,text):elementself.find_element(loc)element.send_keys(text)def full_path(self,filename):current_dir os.getcwd()# 确保文件名加上.txt扩展名if not filename.endswith(.txt):filename .txtfull_path os.path.join(current_dir, filename)return full_pathdef clipboard_content_to_file(self,filename):full_path self.full_path(filename)clipboard_text pyperclip.paste()with open(full_path, w, encodingutf-8) as file:file.write(clipboard_text)print(f剪贴板内容已成功写入到文件: {filename})def read_line_from_file(self,filename):full_path self.full_path(filename)numeric_line None # 初始化为None表示尚未找到符合条件的行try:with open(full_path, r, encodingutf-8) as file:for line in file:# 检查行是否以数字开头if line.strip().startswith(tuple(0123456789)):numeric_line line.rstrip(\n) # 找到第一行后移除行尾的换行符并赋值break # 终止循环except FileNotFoundError:print(f文件 {filename} 未找到。)except Exception as e:print(f读取文件时发生错误: {e})print(读取当前行,numeric_line)return numeric_linedef del_line_from_file(self, filename):full_path self.full_path(filename)numeric_line None # 初始化为None表示尚未找到符合条件的行lines_to_write_back [] # 用于存储除了被删除行外的所有行try:with open(full_path, r, encodingutf-8) as file:found False # 标记是否已找到并处理符合条件的行for line in file:if not found and line.strip().startswith(tuple(0123456789)):numeric_line line.rstrip(\n) # 找到第一行后移除行尾的换行符并赋值found True # 设置标志表示已找到并处理了符合条件的行else:lines_to_write_back.append(line) # 其他行保留准备写回文件if found: # 只有在确实找到并处理了符合条件的行后才重写文件with open(full_path, w, encodingutf-8) as file:file.writelines(lines_to_write_back)except FileNotFoundError:print(f文件 {filename} 未找到。)except Exception as e:print(f读取或修改文件时发生错误: {e})print(删除当前行, numeric_line)return numeric_linedef append_content_to_file(self,filename, content):full_path self.full_path(filename)try:with open(full_path, a, encodingutf-8) as file:file.write(content \n) # 内容后添加换行符以便于区分多条内容print(f内容已成功追加到文件: {filename})except Exception as e:print(f写入文件时发生错误: {e}) 测试用的代码都通过了。 url https://kimi.moonshot.cn/ case BasePage() case.open_url(url) #lowImage___hU90c # img_locBy.CLASS_NAME, login____RTRY # img_locBy.CLASS_NAME, lowImage___hU90c # # if case.click_element(img_loc): # print(ok) edit_loc By.XPATH,//div[data-slate-nodeelement] text你好吗 case.send_text(edit_loc,text) send_locBy.ID, send-button case.click_element(send_loc) case.keep_browser_open() 3.page层 分析因为我计划用于kimi或讯飞或其他所以在规划时。计划用主域名当成关键字。而每一部分不再分成独立模块如登录主页等。如何有跳转的话后期根据情况写在base层。 import time from class_learn.base.base_page import BasePage from selenium.webdriver.common.by import By import pyperclip import osclass KimiPage(BasePage):def __init__(self):super().__init__() # 假设BasePage也有初始化driver的逻辑则需要调用super().__init__()def web_ready(self,url,ok_loc,nok_loc):if self.open_url(url):if self.find_element(ok_loc):print(发现头像登录成功)else:self.click_element(nok_loc)def new_page(self,new_loc):self.click_element(new_loc)time.sleep(2)def get_questions(self, op_loc, op_loc1, edit_loc, keywords, send_loc, copy_loc):self.click_element(op_loc)time.sleep(1)self.click_element(op_loc1)time.sleep(1)self.set_text(edit_loc, keywords)self.click_element(send_loc)time.sleep(2)self.click_element(copy_loc)def set_text_and_send(self,edit_loc,text,send_loc):self.click_element(edit_loc)time.sleep(1)self.set_text(edit_loc,text)self.click_element(send_loc)def click_copy_and_save(self,copy_loc):passcase KimiPage() url https://kimi.moonshot.cn/ nok_locBy.CLASS_NAME, login____RTRY #未登录 ok_locBy.CLASS_NAME, lowImage___hU90c #已登录 case.web_ready(url,ok_loc,nok_loc)new_locBy.XPATH,//div[data-testidmsh-sidebar-new] case.new_page(new_loc)op_locBy.CSS_SELECTOR,.icon___zTPKp svg op_loc1By.CSS_SELECTOR,.itemContainer___eYZxh .content___EPfWU op_loc2By.CSS_SELECTOR,div:nth-child(2) .itemContainer___eYZxh .content___EPfWU edit_locBy.XPATH,//div[data-slate-nodeelement] keywords泌尿系统 send_locBy.ID, send-button copy_locBy.XPATH, //span[contains(.,复制)] # case.get_questions(op_loc,op_loc1,edit_loc,keywords,send_loc,copy_loc) # case.clipboard_content_to_file(keywords) filekeywords_ques for i in range(100):if i%100:case.new_page(new_loc)time.sleep(2)askcase.read_line_from_file(keywords)case.get_questions(op_loc,op_loc2,edit_loc,ask,send_loc,copy_loc)case.del_line_from_file(keywords)case.append_content_to_file(file, f第{i}章 {ask})case.append_content_to_file(file,pyperclip.paste()) case.keep_browser_open() 基本完成了可以自动生成100个问题自动回答自动追加到文本中自动删除已经回答过的问题。方便系统错误后接着进行每10个问题自动开始一个新的页面。 感觉比原来好用多了。清晰了看来代码要不停的写才可以。
http://www.hkea.cn/news/14426780/

相关文章:

  • wordpress类似网站wordpress高级套餐
  • 营销网站的建设流程辽宁省建设工程信息网专家库怎么入
  • 网站建设丿金手指花总9科网站建设
  • 给别人做设计的网站深圳网站优化课程哪里学
  • 山东一建建设有限公司网站首页小件加工平台
  • 兼职网站开发一个月找源码的网站
  • 护肤品网站建设需求分析十五种常见的销售策略
  • 四川省建设厅官方培训网站wordpress近期文章怎么显示时间
  • 湘潭手机网站wordpress the_field
  • 济南网站地址外贸网站建设 广州
  • 网站开发一般黄了新媒体营销策略分析
  • 做ppt很有创意的网站wordpress 谷歌插件
  • 东莞建设网站公司哪家好沈阳外贸网站制作公司
  • 网站搜索引擎优化教程wordpress子域名站点
  • 碧辉腾乐 网站建设合肥 企业网站设计
  • 如何做二级域名子目录网站龙岗区建设工程交易中心
  • 响应式网站建设原则哪里有网站建设加工
  • 网站上的3d产品展示怎么做wordpress 4.9.5
  • 哪个网站科技新闻好百度竞价是什么工作
  • 网站 页面 结构wordpress微信网站模板
  • pc网站案例建网通
  • 购物网站建设优缺点新品上市怎么做宣传推广
  • 招投标 网站建设 山西网站建设力度
  • 微信登录建设银行网站高邮网站建设
  • 项目案例 化妆品网站普通人开网店赚钱吗
  • 上海网站seo诊断西安注册公司多少钱
  • 外贸做哪些网站平台好地区性中介类网站建设
  • 做网站赚不到钱了做一个门户网站多少钱
  • 晋江网站网站建设山西传染病最新消息今天
  • 中象做网站怎么样光谷做网站推广怎么样