简体   繁体   中英

Python: upload images

Can python upload images onto the internet and provide a URL for it? For example is it possible for python to upload an image onto photobucket or any other uploading image service and then retreive the URL for it?

Certainly. You'll need to find an image hosting service with an API (hint: Flickr ), and then write some Python code to interact with it (hint: XML-RPC ).

Pseudocode

import xmlrpclib

with open( "..." ) as imagelist:
    for image in imagelist:
        message = xmlrpclib.make_some_message_or_other
        response = message.send( )
        response.parse( )

You'll need a more specific question if you want a more specific answer!

Sure!

To do it, you basically have to have Python pretend to be a web browser. You need to go get the upload form, fill in all the fields, and pick your image. Then you need to submit the form data, uploading the image. Once that's done, you need to get the "upload complete" page from the site, and find the URL where the image went.

A good library to start with might be the Python version of Perl's famous WWW::Mechanize module. The library is basically a programmable Web browser that you can script in Python.

EDIT: If you plan to do this a lot, you probably do want to use an actual supported API. Otherwise the image hoster might get mad that your python bot is spamming their site.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM