Upload file to a website via Python script

那年仲夏 提交于 2019-12-24 09:16:27

问题


I want to upload a file from my computer to a file hoster like hotfile.com via a Python script. Because Hotfile is only offering a web-based upload service (no ftp).

I need Python first to login with my username and password and after that to upload the file. When the file transfer is over, I need the Download and Delete-link (which is generated right after the Upload has finished).

Is this even possible? If so, can anybody tell me how the script looks like or even give my hints how to build it? Thanks


回答1:


For a similar task, I've previously used mechanize, with some quite success.
Note: although I was not uploading files, its documentation says that it is capable to handle also file uploads.




回答2:


Okay, you want to use Python to upload a file using HTTP "put". You will need to use a Python library that lets you do HTML stuff; a good choice might be httplib which is included with Python.

A Google search for "Python HTTP put" found me this:

http://inamidst.com/proj/put/put.py

This appears to be complete working code that solves your problem.




回答3:


You mention they do not offer FTP, but I went to their site and found the following:

How to upload with FTP? ftp.hotfile.com user: your hotfile username pass: your hotfile password You can upload and make folders, but cant rename,move files

Try it. If it works, using FTP from within Python will be a very simple task.



来源:https://stackoverflow.com/questions/1993060/upload-file-to-a-website-via-python-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!