python上传文件方法总结
【摘要】
python上传文件方法总结
# coding=utf-8""" @Project :pachong-master @File :uploadFile.py @Author :gaojs @Date :2022/5/16 21:04 @Blogs : https://www.g...
python上传文件方法总结
-
# coding=utf-8
-
"""
-
@Project :pachong-master
-
@File :uploadFile.py
-
@Author :gaojs
-
@Date :2022/5/16 21:04
-
@Blogs : https://www.gaojs.com.cn
-
"""
-
from time import sleep
-
-
import pyautogui
-
from win32com.client import Dispatch
-
from pywinauto.keyboard import send_keys, SendKeys
-
from selenium import webdriver
-
import pywinauto
-
-
-
class UploadFile:
-
-
def __init__(self):
-
"""
-
上传文件
-
"""
-
self.driver = webdriver.Chrome()
-
self.driver.get('https://www.wenshushu.cn/')
-
self.driver.maximize_window()
-
self.driver.implicitly_wait(10)
-
-
def pywinUpload(self, filePath, filename):
-
"""
-
使用pywinauto上传
-
:return:
-
"""
-
self.driver.find_element_by_css_selector('div.chooice-btn button').click()
-
desk = pywinauto.Desktop()
-
# 点击打开按钮
-
frame = desk["打开"]
-
# 选择文件地址输入框
-
frame["Toolbar3"].click()
-
# 输入路径文件
-
send_keys(filePath)
-
# 键盘输入回车,打开该路径
-
send_keys("{VK_RETURN}")
-
# 选中文件名输入框,输入文件名
-
frame["文件名(&N):Edit"].type_keys(filename)
-
sleep(3)
-
# 点击打开
-
frame["打开(&O)"].click()
-
-
def upload(self, filenamePath):
-
"""
-
input标签才能这样:send_keys上传文件
-
:return:
-
"""
-
upload = self.driver.find_element_by_css_selector('div.chooice-btn button')
-
sleep(3)
-
# loadfile.send_keys(filenamePath)
-
upload.send_keys('filenamePath')
-
self.driver.find_element_by_id('onBtn')
-
-
def win32Upload(self, filenamePath):
-
"""
-
使用win32com.client上传文件
-
:param filenamePath:
-
:return:
-
"""
-
self.driver.find_element_by_css_selector('div.chooice-btn button').click()
-
patch = Dispatch("WScript.shell")
-
sleep(3)
-
patch.Sendkeys(filenamePath)
-
-
def autoguiUpload(self, filenamePath):
-
"""
-
pyautogui上传文件
-
:param filenamePath:
-
:return:
-
"""
-
self.driver.find_element_by_css_selector('div.chooice-btn button').click()
-
pyautogui.write(filenamePath)
-
sleep(3)
-
# pyautogui.keyDown('enter')
-
# pyautogui.keyUp('enter')
-
pyautogui.press('enter', presses=2)
注意:这个autoguiUpload()方法还没能上传成功,正在思考…emo
文章来源: blog.csdn.net,作者:懿曲折扇情,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/qq_41332844/article/details/126837426
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)