Python在webbrows上上传

2024-10-02 12:33:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在写一个脚本,将上传文件从我的本地机器到一个网页。这是url:https://tutorshelping.com/bulkask,还有一个上传选项。但是我不知道怎么上传。你知道吗

我当前的脚本:

import webbrowser, os

def fileUploader(dirname):
    mydir = os.getcwd() + dirname
    filelist = os.listdir(mydir)
    for file in filelist:
        filepath = mydir + file #This is the file absolte file path
        print(filepath)

    url = "https://tutorshelping.com/bulkask"
    webbrowser.open_new(url)  # open in default browser
    webbrowser.get('firefox').open_new_tab(url)


if __name__ == '__main__':
    dirname = '/testdir'
    fileUploader(dirname)

Tags: inhttps脚本comurlosopenfile
2条回答

我认为pythonwebbrowser包除了打开一个带有特定url的浏览器/选项卡之外,什么都做不了。你知道吗

如果我理解你的问题,你想打开网页,设置文件上传,然后模拟一个按钮点击。你可以试试pyppeteer。你知道吗

免责声明:我从未使用过Python版本,只有JS版本(puppeter)。

一个快速的解决方案是使用类似AppRobotic的个人宏软件,或者直接与Windows弹出窗口和应用程序交互,或者只使用X、Y坐标移动鼠标,单击按钮,然后发送键盘键以在文件中键入或制表符。你知道吗

这样的东西在调整后会起作用,因此它会在您准备好单击“上载”按钮并浏览文件时运行:

import win32com.client
x = win32com.client.Dispatch("AppRobotic.API")
import webbrowser

# specify URL
url = "https://www.google.com"

# open with default browser
webbrowser.open_new(url) 

# wait a bit for page to open
x.Wait(3000)
# use UI Item Explorer to find the X,Y coordinates of Search box
x.MoveCursor(438, 435)
# click inside Search box
x.MouseLeftClick

x.Type("AppRobotic")
x.Type("{ENTER}")

相关问题 更多 >

    热门问题