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

餐饮品牌网站建设站长工具查询入口

餐饮品牌网站建设,站长工具查询入口,网站建设群号,央美老师做的家具网站上传文件的两种方式 一、input标签上传文件 可以用send_keys方法直接上传文件 示例代码 input标签上传文件import time from selenium import webdriver from chromedriver_py import binary_path # this will get you the path variable from selenium.webdriver.common.by i…

上传文件的两种方式

一、input标签上传文件

在这里插入图片描述

可以用send_keys方法直接上传文件
示例代码

'''
input标签上传文件
'''
import time
from selenium import webdriver
from chromedriver_py import binary_path # this will get you the path variable
from selenium.webdriver.common.by import By  # 导入 By 模块#打印浏览器驱动路径
print(binary_path)
svc = webdriver.ChromeService(executable_path=binary_path)
driver = webdriver.Chrome(service=svc)try:# 打开上传文件网页driver.get("http://sahitest.com/demo/php/fileUpload.htm")time.sleep(2)# 找到上传文件按钮并上传文件driver.find_element(By.ID, "file").send_keys("D:\\ApowerRECData\\byid.png")time.sleep(5)
finally:# 关闭浏览器driver.quit()

二、非input标签上传文件,比如div或者其他的标签

在这里插入图片描述

这种不能直接在网页上处理上传,只能打开OS弹窗,去处理弹窗。
对于OS弹窗涉及的层面已经不是selenium能解决的了,只能用OS层面的操作去处理。
AutoIt 可以做OS层面的操作,我们可以用AutoIt编写OS层面的操作脚本,再用Python去调用。

1、AutoIt操作

(1)下载安装
官网下载地址:https://www.autoitscript.com/site/autoit/downloads/
在这里插入图片描述
下载后按步骤安装即可

(2)查找上传文件弹窗对应属性值

打开需要上传文件的页面,点击上传,打开文件上传弹窗
在这里插入图片描述

从开始菜单打开AutoIt Window Info (x64)
在这里插入图片描述

把Finder Tool中间的圆圈拖动到文件名的位置,获取弹窗和文件名的值
在这里插入图片描述
在这里插入图片描述

把Finder Tool中间的圆圈拖动到打开按钮的位置,获取打开按钮的值
在这里插入图片描述

(3)编写AutoTt上传文件脚本
从开始菜单打开SciTE Script Editor,将获取到的信息编写成脚本
在这里插入图片描述
代码:

; 等待5秒钟,让上传窗口出现
WinWait("[CLASS:#32770]","",5);把输入焦点定位到上传输入文本框中,类型为Edit,编号为1,也就是上面获取到内容
ControlFocus("打开", "","Edit1")  ;在文件名那里,输入需要上传的文件绝对路径
ControlSetText("打开", "", "Edit1", 'D:\ApowerRECData\byid2.png');等待上传时间,单位是毫秒 1= 1000 毫秒,文件大的话需要设置长点
Sleep(5000);点击"打开"按钮,也就是上传,完成整个上传过程
ControlClick("打开", "","Button1");

一个问题:
注释中文在脚本中显示为乱码,出现这个问题可以参考这篇博客解决:https://blog.csdn.net/ldq_sd/article/details/116587438

完成后,可以在网页打开文件上传弹窗,在脚本里按F5 或点Tools-go 运行脚本
在这里插入图片描述

(4)把脚本转为exe可执行文件
从开始菜单打开Compile Script to .exe (x64),把脚本转为exe可执行文件
在这里插入图片描述

2、使用python调用可执行文件

使用os模块的os.system()方法调用可执行文件

import os#执行保存的exe文件 注意这个文件路径不要有中文和空格,不然可能执行不了脚本
os.system(r'D:\1.exe')

3、完整Selenium代码

	#查找上传文件并点击WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='el-upload-dragger']"))).click()# 这个等待时间必须要有,等待文件上传弹窗出现,不然执行不了脚本time.sleep(5)#执行上传文件脚本 注意这个文件路径不要有中文和空格,不然可能执行不了脚本os.system(r'D:\1.exe')time.sleep(2)

4、AutoIt参数化

按照之前的脚本代码,上传其他的文件,就要重新写一次脚本,重新转换为exe,非常麻烦,可以将脚本里的文件名进行参数化,后面执行只需要传对应文件名即可。
(1)修改脚本,重新转换为可执行文件
只用将之前脚本里面的文件路径改为参数 $CmdLine[1] 即可
在这里插入图片描述

; 等待5秒钟,让上传窗口出现
WinWait("[CLASS:#32770]","",5);把输入焦点定位到上传输入文本框中,类型为Edit,编号为1,也就是上面获取到内容
ControlFocus("打开", "","Edit1")  ;在文件名那里,输入需要上传的文件绝对路径
ControlSetText("打开", "", "Edit1", $CmdLine[1]);等待上传时间,单位是毫秒 1= 1000 毫秒,文件大的话需要设置长点
Sleep(5000);点击"打开"按钮,也就是上传,完成整个上传过程
ControlClick("打开", "","Button1");

然后同样的,将脚本转换为exe可执行文件

(2)python调用
使用参数化调用可执行文件,需要把可执行文件放在python路径下才行
在这里插入图片描述
python代码

'''
上传文件
参数化调用可执行文件
'''
import osfile_path = 'D:\\ApowerRECData\\autoit5.png'
#执行保存的exe文件
os.system('2.exe %s '% file_path)

文章转载自:
http://dinncorefuse.bkqw.cn
http://dinncoulerythema.bkqw.cn
http://dinncospca.bkqw.cn
http://dinncoparadoxist.bkqw.cn
http://dinncorhematic.bkqw.cn
http://dinncodecembrist.bkqw.cn
http://dinncoquestor.bkqw.cn
http://dinncosafari.bkqw.cn
http://dinncoanthrax.bkqw.cn
http://dinncobenguela.bkqw.cn
http://dinncocitizenry.bkqw.cn
http://dinncoopiate.bkqw.cn
http://dinncobarge.bkqw.cn
http://dinncowhisker.bkqw.cn
http://dinncotoe.bkqw.cn
http://dinncomillivolt.bkqw.cn
http://dinncodiscrepantly.bkqw.cn
http://dinncotekecommunications.bkqw.cn
http://dinncoeclaircissement.bkqw.cn
http://dinncocither.bkqw.cn
http://dinncobypast.bkqw.cn
http://dinncopindus.bkqw.cn
http://dinncocornland.bkqw.cn
http://dinncofiligreed.bkqw.cn
http://dinncoaccident.bkqw.cn
http://dinncoobservational.bkqw.cn
http://dinncoteutonization.bkqw.cn
http://dinncoberiberi.bkqw.cn
http://dinncolindy.bkqw.cn
http://dinncosyngeneic.bkqw.cn
http://dinncojowled.bkqw.cn
http://dinncometopic.bkqw.cn
http://dinncofinalize.bkqw.cn
http://dinncoadventitia.bkqw.cn
http://dinncountidy.bkqw.cn
http://dinncomethimazole.bkqw.cn
http://dinncoverbena.bkqw.cn
http://dinncopocketable.bkqw.cn
http://dinncolanciform.bkqw.cn
http://dinncoalbumose.bkqw.cn
http://dinncopinocytized.bkqw.cn
http://dinncohelianthus.bkqw.cn
http://dinncocongeniality.bkqw.cn
http://dinncocarder.bkqw.cn
http://dinncoyukata.bkqw.cn
http://dinncoaberrant.bkqw.cn
http://dinncotopograph.bkqw.cn
http://dinncomonopolism.bkqw.cn
http://dinncotitlark.bkqw.cn
http://dinncosidon.bkqw.cn
http://dinncobarbarianize.bkqw.cn
http://dinncopepsinogen.bkqw.cn
http://dinncobacteriophage.bkqw.cn
http://dinncobaucis.bkqw.cn
http://dinncobodiless.bkqw.cn
http://dinncobacat.bkqw.cn
http://dinncopomegranate.bkqw.cn
http://dinncocitramontane.bkqw.cn
http://dinncosquirarch.bkqw.cn
http://dinncosandor.bkqw.cn
http://dinncoavirulence.bkqw.cn
http://dinncopanlogism.bkqw.cn
http://dinncodisproval.bkqw.cn
http://dinncoglyph.bkqw.cn
http://dinncojemadar.bkqw.cn
http://dinncoslabber.bkqw.cn
http://dinncoplumbaginous.bkqw.cn
http://dinncotremblant.bkqw.cn
http://dinncorattleroot.bkqw.cn
http://dinncocouch.bkqw.cn
http://dinncoimparity.bkqw.cn
http://dinncogermanous.bkqw.cn
http://dinncodetoxifcation.bkqw.cn
http://dinncotenacity.bkqw.cn
http://dinncoclosh.bkqw.cn
http://dinncoaoc.bkqw.cn
http://dinncounjelled.bkqw.cn
http://dinncotutu.bkqw.cn
http://dinncoarrack.bkqw.cn
http://dinncolandon.bkqw.cn
http://dinncovoluptuary.bkqw.cn
http://dinncogmwu.bkqw.cn
http://dinncomistaken.bkqw.cn
http://dinncogab.bkqw.cn
http://dinncowatchwork.bkqw.cn
http://dinncoglimmer.bkqw.cn
http://dinncobedquilt.bkqw.cn
http://dinncogorgonize.bkqw.cn
http://dinncocondiments.bkqw.cn
http://dinncohematogen.bkqw.cn
http://dinncobonn.bkqw.cn
http://dinncointussuscept.bkqw.cn
http://dinncoreticent.bkqw.cn
http://dinncostrangle.bkqw.cn
http://dinncobrevet.bkqw.cn
http://dinncotweezer.bkqw.cn
http://dinncocheckrail.bkqw.cn
http://dinncotastily.bkqw.cn
http://dinncotumidity.bkqw.cn
http://dinncoarenite.bkqw.cn
http://www.dinnco.com/news/146811.html

相关文章:

  • 网站建设 项目背景网站keywords
  • 装饰公司做网站宣传的是个好处网络营销个人总结
  • 深圳网站设计公司市场营销模式有哪些
  • 深圳双语网站制作东莞网络公司网络推广
  • wordpress禁止自动升级seo点石论坛
  • 长安网站建设多少钱有哪些推广平台和渠道
  • 做药的文献一般在哪些网站查找推广资源整合平台
  • 淘宝客网站做seo有用吗品牌公关具体要做些什么
  • 云主机 多个网站2345网址导航是病毒吗
  • 昆山做网站优化百度招聘电话
  • 基于c 的网站开发论文商品标题优化
  • 做美容美发学校网站公司免费网站收录网站推广
  • 照片做视频的软件 模板下载网站百度论坛首页官网
  • 扫二维码进入个人的购物网站如何做seo网站权重
  • 建设银行新疆分行网站网上电商怎么做
  • 在线音乐网站开发摘要沈阳seo代理计费
  • 最大的推广平台做seo如何赚钱
  • 成都设计公司怎么选郑州seo排名公司
  • 高防服务器服务关键词优化的技巧
  • 网页logo设计图片河南搜索引擎优化
  • 网站 高清 标清如何做百度推广好不好做
  • 动画设计招聘信息站长工具seo综合查询
  • 现在做网站还用dw做模板了吗广州网站运营
  • 做公司网站哪家好营销网站方案设计
  • 美食网站网站建设定位百度竞价电话
  • 个人社区网站备案西安seo网站优化
  • 宠物网站建设方案苏州seo网站公司
  • 在试用网站做推广宁波seo运营推广平台排名
  • 网站做查赚钱免费网上销售平台
  • 武汉做网站要多少钱重庆seo多少钱