473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Need help translating Ruby code

Hi I am new to Ruby from Python and am still learning some stuff. I
have a Ruby program that uses the mechanize library to connect to a Web
site and authenticate with a username and password. The issue I have is
that I need to get this code translated into Python. The Python
mechanize library is not very well documented and I was wondering if
anyone here had any experience using this library in Ruby or Python.
Basically the only tricky part of this program is that it needs to add a
field to the form on the page. This extra field, "__EVENTTARGET", needs
to be added explicitly. I cannot find the Python equivalent to the
WWW::Mechanize::Form::Field.new(nil,nil) method. Thank you in advance.
I hope I explained myself well.

Expand|Select|Wrap|Line Numbers
  1. require 'rubygems'
  2. require 'mechanize'
  3.  
  4. Hpricot.buffer_size = 262144
  5.  
  6. auth = {
  7.   :username => "bugmenot2008@yahoo.com",
  8.   :password => "letmeinalready"
  9. }
  10.  
  11. login_url = "http://www.princetonreview.com/Login3.aspx?uidbadge=" # !>
  12. `&' interpreted as argument prefix
  13. agent  = WWW::Mechanize.new
  14. page = agent.get( login_url )
  15. my_form = page.forms.first
  16.  
  17. my_form['ctl00$MasterMainBodyContent$txtUsername']= auth[:username]
  18. my_form['ctl00$MasterMainBodyContent$txtPassword']= auth[:password]
  19.  
  20.  
  21. target_field = WWW::Mechanize::Form::Field.new(nil,nil)
  22. target_field.name = "__EVENTTARGET"
  23. target_field.value  = "ctl00$MasterMainBodyContent$btnLogin"
  24. my_form.fields << target_field
  25.  
  26. new_page = my_form.submit
  27.  
  28. # examine output to make sure it worked
  29. new_page = agent.get("http://www.princetonreview.com/YourStuff.aspx")
  30.  
  31. pp new_page
  32.  
Sep 9 '08 #1
1 3181
xenoix
15
auth = {
:username => "bugmenot2008@yahoo.com",
:password => "letmeinalready"
}
I wonder if thats a real username/password...
Sep 2 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Graham Nicholls | last post by:
Hi, I'm trying to size a jpeg file. The file size is held in a short (2 byte integer) at a certain offset. Once I've found these two bytes (they're in MSB,LSB order), I need to convert them to...
220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
54
by: Brandon J. Van Every | last post by:
I'm realizing I didn't frame my question well. What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump up in your chair and scream "Wow! Ruby has *that*? That is SO...
30
by: Christian Seberino | last post by:
How does Ruby compare to Python?? How good is DESIGN of Ruby compared to Python? Python's design is godly. I'm wondering if Ruby's is godly too. I've heard it has solid OOP design but then...
7
by: Mike Kamermans | last post by:
I hope someone can help me, because what I'm going through at the moment trying to edit XML documents is enough to make me want to never edit XML again. I'm looking for an XML editor that has a...
65
by: Amol Vaidya | last post by:
Hi. I am interested in learning a new programming language, and have been debating whether to learn Ruby or Python. How do these compare and contrast with one another, and what advantages does one...
92
by: Ray | last post by:
I just moved to another company that's mainly a Java/.NET shop. I was happy to find out that there's a movement from the grassroot to try to convince the boss to use a dynamic language for our...
26
by: brenocon | last post by:
Hi all -- Compared to the Python I know and love, Ruby isn't quite the same. However, it has at least one terrific feature: "blocks". Whereas in Python a "block" is just several lines of...
10
by: bruce | last post by:
hi... can someone point me to where/how i would go about calling a ruby app from a python app, and having the python app being able to get a returned value from the ruby script. something...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.