How to interact with web pages?

Discussion in 'Ruby' started by Yu-Hsuan Lai, Dec 23, 2010.

  1. Yu-Hsuan Lai

    Yu-Hsuan Lai Guest

    My teacher assigned a task to me. In short, it is to use a not
    friendly web interface to upload many pictures(once a file).
    As a ruby novice, I think that it can be automatized.
    But I even don't know where to start.
    How to send a POST Http request? How to ensure my pictures have been
    upload completely? If the system requires me to login(it does), what
    should I do with session?

    Need some advise.

    --
    Lai, Yu-Hsuan
    Yu-Hsuan Lai, Dec 23, 2010
    #1
    1. Advertising

  2. Yu-Hsuan Lai

    John Morrice Guest

    > My teacher assigned a task to me. In short, it is to use a not
    > friendly web interface to upload many pictures(once a file).
    > As a ruby novice, I think that it can be automatized.
    > But I even don't know where to start.
    > How to send a POST Http request? How to ensure my pictures have been
    > upload completely? If the system requires me to login(it does), what
    > should I do with session?
    >
    > Need some advise.


    Do some homework before asking others! Wait, is your homework to write
    the ruby program, or are you just automating the process of doing your
    homework?

    Here is my advice: in general, network communication, even over an
    application layer protocol like http, isn't a "novice" topic. There
    may be libraries that make it easier. But I just don't consider it to
    be a trivial task - even if those libraries could do it in one
    line.

    For a small example of something that can go wrong: say your script
    downloads an incorrect URL - you expect a 404 back, right?

    Well, some ISPs will give you back a custom 404 page, which looks like
    a 404 to a human sitting at GUI, but actually has status 200 OK, so
    your script thinks the page exists. I wrote a web crawler library once,
    and had a awful bother trying to debug that one, before I realised what
    was happening.

    IMO, with network programming, unfortunately the SNAFU
    abbreviation often applies.

    Here's some more advice: learn to do your own research. A quick google
    search for "ruby http post image" turned up a very similar stack
    overflow question - it was the first hit.

    It also has many answers from different points of view. Here it is:
    http://stackoverflow.com/questions/184178/ruby-how-to-post-a-file-via-http-as-multipart-form-data

    They give lots of examples, but in short, the libraries mentioned
    in the answers are:

    Technoweenie's rest-client,
    this one did it in one line, but the link doesn't seem to work.

    Nick Sieger's multipart-post
    https://github.com/nicksieger/multipart-post/tree

    Curb - ruby curl bindings
    http://curb.rubyforge.org/

    Net::HTTP - ruby standard library http bindings
    Look that up here
    http://ruby-doc.org/ruby-1.9/index.html

    Have fun and shiny learnings,
    Johnny
    John Morrice, Dec 23, 2010
    #2
    1. Advertising

  3. Yu-Hsuan Lai

    Josh Cheek Guest

    [Note: parts of this message were removed to make it a legal post.]

    I'll also add Mechanize, if you don't need JavaScript (
    http://rubygems.org/gems/mechanize)
    One of the Mechanize examples is exactly what you are talking about, logging
    in to flickr and uploading an image (
    https://github.com/tenderlove/mechanize/blob/master/examples/flickr_upload.rb
    )
    A good starting place for a newbie might be to figure out how to modify that
    script. But be warned that it might take a lot of playing around and reading
    documentation. I'll suggest loading irb, and playing around in there to see
    what works and how to get to the next spot from where you are at.

    If you do need JavaScript, I like Watir a lot. But you have to know a little
    more what you are doing to use Watir (maybe not if you are using Internet
    Explorer, I'm on a Mac so never tried with IE). When I did it with FireFox,
    I had to load up FireFox from the command line with special arguments, and
    when I did it with Chrome, I had to download and install some Chrome add ons
    (fwiw, the FireFox one was way more stable). Here is a video I made for a
    class where I tried to use Watir to test a site my team was working on (
    http://vimeo.com/16965368). In the end, I didn't keep using it, but you can
    see that it should be able to do what you are asking.
    Josh Cheek, Dec 23, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. lltaylor
    Replies:
    1
    Views:
    370
    Steve C. Orr [MVP, MCSD]
    Jun 30, 2004
  2. Steve
    Replies:
    10
    Views:
    678
    Steve
    Jul 13, 2005
  3. Nathan Sokalski
    Replies:
    5
    Views:
    976
    Gaurav Vaish \(www.Edujini-Labs.com\)
    Jan 10, 2007
  4. beginner
    Replies:
    12
    Views:
    444
    Diez B. Roggisch
    Aug 2, 2007
  5. Nathan Sokalski
    Replies:
    4
    Views:
    260
    Nathan Sokalski
    Dec 21, 2006
Loading...

Share This Page