473,581 Members | 2,785 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help translating Ruby code

7 New Member
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.ne w(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 3192
xenoix
15 New Member
auth = {
:username => "bugmenot2008@y ahoo.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
11033
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 an integer - now I know that in C I'd just cast a pointer to the offset to a short, and that python doesn't cast, so how can I extract the value from...
220
18931
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 any preconceived ideas about it. I have noticed, however, that every programmer I talk to who's aware of Python is also talking about Ruby. So it...
54
6535
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 FRICKIN' COOL!!! ***MAN*** that would save me a buttload of work and make my life sooooo much easier!" As opposed to minor differences of this feature...
30
3423
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 I've also heard there are lots of weird ways to do some things kinda like Perl which is bad for me. Any other ideas?
7
4376
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 few features that you'd expect in any editor, except nearly none of them seem to have: 1 - Search and repalce with Regular Expressions. 2 - ...
65
5491
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 language provide over the other? I would like to consider as many opinions as I can on this matter before I start studying either language in depth....
92
4334
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 development! Two of the senior developers, however, are already rooting for Ruby on Rails--although they haven't tried RoR themselves. When I...
26
2697
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 locally-scoped-together code, in Ruby a "block" defines a closure (anonymous function). To avoid confusion let's call them Ruby block-closures. I see...
10
1495
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 like test.py a = os.exec(testruby.rb)
0
7804
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7910
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8180
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6563
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5366
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3832
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2307
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1409
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1144
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.