How to interact with web pages?
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.
Re: How to interact with web pages?
> 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
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
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
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:
They give lots of examples, but in short, the libraries mentioned
in the answers are:
this one did it in one line, but the link doesn't seem to work.
Nick Sieger's multipart-post
Curb - ruby curl bindings
Net::HTTP - ruby standard library http bindings
Look that up here
Have fun and shiny learnings,
Re: How to interact with web pages?
[Note: parts of this message were removed to make it a legal post.]
One of the Mechanize examples is exactly what you are talking about, logging
in to flickr and uploading an image (
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.
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.
|All times are GMT. The time now is 06:14 AM.|
Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.