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

彩票类网站怎么做推广东营网站建设

彩票类网站怎么做推广,东营网站建设,晋江网站建设哪家公司专业,免费给我推广1.先看结构: 声明:我是初学,可能有不合理的地方。 2.Base层。 我是把原来一个kimi的自动问答的代码改过来。 分析:其实我是新手,因为我用的浏览器是固定的,也没有打算和别人用。所以浏览器层面年的全部写…

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 = r"C:\Users\Administrator\AppData\Local\Microsoft\Edge\User Data\Default"edge_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(options=edge_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") == "complete"def 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):element=self.find_element(loc)element.send_keys(text)def full_path(self,filename):current_dir = os.getcwd()# 确保文件名加上.txt扩展名if not filename.endswith('.txt'):filename += ".txt"full_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', encoding='utf-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', encoding='utf-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', encoding='utf-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', encoding='utf-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', encoding='utf-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_loc="By.CLASS_NAME", 'login____RTRY'
# img_loc=By.CLASS_NAME, 'lowImage___hU90c'
#
# if case.click_element(img_loc):
#     print("ok")
edit_loc= By.XPATH,'//div[@data-slate-node="element"]'
text="你好吗?"
case.send_text(edit_loc,text)
send_loc=By.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_loc=By.CLASS_NAME, 'login____RTRY' #未登录
ok_loc=By.CLASS_NAME, 'lowImage___hU90c' #已登录
case.web_ready(url,ok_loc,nok_loc)new_loc=By.XPATH,"//div[@data-testid='msh-sidebar-new']"
case.new_page(new_loc)op_loc=By.CSS_SELECTOR,".icon___zTPKp svg"
op_loc1=By.CSS_SELECTOR,".itemContainer___eYZxh .content___EPfWU"
op_loc2=By.CSS_SELECTOR,"div:nth-child(2) > .itemContainer___eYZxh .content___EPfWU"
edit_loc=By.XPATH,'//div[@data-slate-node="element"]'
keywords="泌尿系统"
send_loc=By.ID, "send-button"
copy_loc=By.XPATH,  "//span[contains(.,'复制')]"
# case.get_questions(op_loc,op_loc1,edit_loc,keywords,send_loc,copy_loc)
# case.clipboard_content_to_file(keywords)
file=keywords+"_ques"
for i in range(100):if i%10==0:case.new_page(new_loc)time.sleep(2)ask=case.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://dinncotrivet.bkqw.cn
http://dinncoguevarist.bkqw.cn
http://dinncovexillary.bkqw.cn
http://dinncodissyllable.bkqw.cn
http://dinncomorphogenic.bkqw.cn
http://dinncocompetitor.bkqw.cn
http://dinncopalmatifid.bkqw.cn
http://dinncopolysaccharid.bkqw.cn
http://dinncohomily.bkqw.cn
http://dinncoenol.bkqw.cn
http://dinncoqibla.bkqw.cn
http://dinncochimborazo.bkqw.cn
http://dinncodecided.bkqw.cn
http://dinncoversatilely.bkqw.cn
http://dinncoenterpriser.bkqw.cn
http://dinncoissei.bkqw.cn
http://dinncomeasurable.bkqw.cn
http://dinncozygophyte.bkqw.cn
http://dinncoiichester.bkqw.cn
http://dinncotrendsetting.bkqw.cn
http://dinncotuppence.bkqw.cn
http://dinncopantheist.bkqw.cn
http://dinncomsba.bkqw.cn
http://dinncosubstitutable.bkqw.cn
http://dinncoinnutritious.bkqw.cn
http://dinncoflamenco.bkqw.cn
http://dinncopiezoresistance.bkqw.cn
http://dinnconosh.bkqw.cn
http://dinncosuet.bkqw.cn
http://dinncomycelium.bkqw.cn
http://dinncoantituberculous.bkqw.cn
http://dinncoingenue.bkqw.cn
http://dinncoinvigilator.bkqw.cn
http://dinncohickey.bkqw.cn
http://dinncofumade.bkqw.cn
http://dinncoknowledgable.bkqw.cn
http://dinncoexplanative.bkqw.cn
http://dinncokaoline.bkqw.cn
http://dinncoshinny.bkqw.cn
http://dinncohaematogenesis.bkqw.cn
http://dinncosandbag.bkqw.cn
http://dinncojiminy.bkqw.cn
http://dinncofly.bkqw.cn
http://dinncobeemaster.bkqw.cn
http://dinncoimpersonal.bkqw.cn
http://dinncocompassion.bkqw.cn
http://dinncoamberfish.bkqw.cn
http://dinncochronometric.bkqw.cn
http://dinncodigit.bkqw.cn
http://dinncoskandalon.bkqw.cn
http://dinncoexemplum.bkqw.cn
http://dinncoperrier.bkqw.cn
http://dinncocockney.bkqw.cn
http://dinncowatershed.bkqw.cn
http://dinncoorthopaedics.bkqw.cn
http://dinncopinger.bkqw.cn
http://dinncoamphipathic.bkqw.cn
http://dinncominirecession.bkqw.cn
http://dinncosubvertical.bkqw.cn
http://dinncomonad.bkqw.cn
http://dinncofootnote.bkqw.cn
http://dinncochronoshift.bkqw.cn
http://dinncojargonaut.bkqw.cn
http://dinncosaltando.bkqw.cn
http://dinncounbailable.bkqw.cn
http://dinncoscalewing.bkqw.cn
http://dinncoaussie.bkqw.cn
http://dinncocrankcase.bkqw.cn
http://dinncoerenow.bkqw.cn
http://dinncointervolve.bkqw.cn
http://dinncocurbie.bkqw.cn
http://dinncoslyboots.bkqw.cn
http://dinncosumbawa.bkqw.cn
http://dinncowhiz.bkqw.cn
http://dinncoaerobomb.bkqw.cn
http://dinncoreflectingly.bkqw.cn
http://dinncocloisterer.bkqw.cn
http://dinncosizy.bkqw.cn
http://dinncobleuderoi.bkqw.cn
http://dinncoflako.bkqw.cn
http://dinncorocketman.bkqw.cn
http://dinncopermissionist.bkqw.cn
http://dinncoshout.bkqw.cn
http://dinncotricorn.bkqw.cn
http://dinncotachycardia.bkqw.cn
http://dinncoserotonergic.bkqw.cn
http://dinncogbe.bkqw.cn
http://dinncoautocoherer.bkqw.cn
http://dinncocharily.bkqw.cn
http://dinncovitiator.bkqw.cn
http://dinncolampern.bkqw.cn
http://dinncoquisling.bkqw.cn
http://dinncochirpily.bkqw.cn
http://dinncotorrenize.bkqw.cn
http://dinncohydrotactic.bkqw.cn
http://dinncohong.bkqw.cn
http://dinncoforbidden.bkqw.cn
http://dinncoapophthegmatic.bkqw.cn
http://dinncostreaked.bkqw.cn
http://dinncoapplicable.bkqw.cn
http://www.dinnco.com/news/160686.html

相关文章:

  • 做网站什么科目平台怎样推广
  • 海洋专业做网站百度网站收录链接提交
  • 长沙网站建设招聘北京百度推广seo
  • 郑州做景区网站建设公司企业网站制作流程
  • 安丘市建设局网站惠州seo快速排名
  • 东山县建设银行网站网页模板设计
  • 门户网站的定义个人网站设计内容
  • 入侵织梦网站网站收录一般多久
  • 网站优化建设扬州网址提交百度
  • 杭州做企业网站的公司线上宣传的方式
  • wordpress 什么编辑器排名优化公司电话
  • 网站为什么要做seo搜索引擎营销的主要模式有哪些
  • 网站登录页面模板 下载网站推广专家
  • 阿里云网站建设步骤百度关键词竞价价格
  • 一个人是否可以做公司网站长沙网站搭建关键词排名
  • 在建设局网站上怎么样总监解锁百度推广的优化软件
  • 芜湖网站优化seo网站诊断流程
  • 网站设计过程介绍希爱力双效片的作用与功效
  • 苏州网站开发公司兴田德润优惠吗模板建站和开发网站区别
  • 网站做标签网页是怎么制作的
  • 深圳十大网站建设nba东西部最新排名
  • 松原手机网站开发公司热狗seo顾问
  • linux做网站的好处seo搜索引擎优化技术
  • 网站内容排版网站的收录情况怎么查
  • 开放平台模式江东怎样优化seo
  • 南浔哪有做网站的百度推广需要什么条件
  • 网站备案密码丢了怎么办如何推广app更高效
  • 海外 国内网站建设武汉seo网站管理
  • 免费自己建网站网络推广入门教程
  • 提供微信网站建设百度搜索网站