有没有办法用Python控制windows?

发布于 2024-12-26 04:52:56 字数 551 浏览 0 评论 0原文

我正在尝试创建一个将文件上传到网站的脚本。我无法控制该网站,因此必须通过单击和键入来上传文件。

又名,

  1. 等待上传窗口弹出,输入
  2. 文件名/路径,
  3. 单击“打开”或“上传”(或其他)按钮,

因为该窗口是操作系统的一部分(不是浏览器窗口),所以我无法使用它来控制它硒或类似的东西(据我所知。如果我错了,请告诉我)。这意味着我需要脚本来执行此操作。

我已经让它在 Windows 上运行(用 AutoIt 制作),但是,我还需要它在 Unix 系统 (Linux) 上运行。

所以我想问一下,有没有办法用Python之类的东西来做到这一点?如果我可以制作一个可以在两者上运行的脚本,那就太棒了(AutoIt 仅适用于 Windows)。

我了解 Java、Python 和 AutoIt,但如果这些都做不到,我可以学习其他东西。

谢谢。

编辑:

好的,显然使用 HTTP POST 是执行此操作的方法,但是我不确定如何执行此操作。我将对此进行更多研究。感谢@Chrules 提醒我注意这一点。

I'm trying to create a script that will upload a file to a website. I have no control of the website so the file has to be uploaded via clicking and typing.

Aka,

  1. wait for upload window to pop up
  2. type name/path of file
  3. click "Open" or "upload" (or whatever) button

Because the window is part of the OS (not a browser window), I can't control it with Selenium or something like that (as far as I know. Plz let me know if I am wrong). This means I need the script to do this.

I already have it working for Windows (made it with AutoIt) however, I also need it to run on Unix systems (Linux).

So I'm asking, is there a way to do it with Python or something? If I can make one script that will run on both, that would be awesome (AutoIt is Windows-only).

I have knowledge of Java, Python and AutoIt, but if none of those can do it, I can learn something else.

Thanks.

EDIT:

Ok, so apparently using HTTP POST is the way to do it, however I am not sure how to do this. I'm going to do more research on that. Thx @Chrules for bring this to my attention.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

葵雨 2025-01-02 04:52:56

现在您想通过 HTTP 请求来完成此操作,Requests 库强烈推荐。

就是这么简单:

>>> url = 'http://httpbin.org/post'
>>> files = {'report.xls': open('report.xls', 'rb')}
>>> r = requests.post(url, files=files)

Now that you want to do it via an HTTP request, the Requests library is highly recommended.

It is really that simple:

>>> url = 'http://httpbin.org/post'
>>> files = {'report.xls': open('report.xls', 'rb')}
>>> r = requests.post(url, files=files)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文