Serial
Serial

Reputation: 8045

Entering into form with Mechanize

Im writing a smaller part of a larger program that is using mechanize to input a YouTube URL into a form but i cant get it to work

Im using the first form on the page nr=0 but i don't what to put in the br[] attribute box since i don't have the name of the form just the id

Here is my code:

import mechanize

url = "Youtube to Mp3 URL"
br = mechanize.Browser()
br.set_handle_robots(False)
br.open(url)
br.select_form(nr=0)
br[?] = "Youtube Video URL" #What goes in the []?
res = br.submit()
content = res.read()
print content

Im sure its a dumb question but none of the other questions are helping me

Thank You!

Upvotes: 0

Views: 557

Answers (1)

PepperoniPizza
PepperoniPizza

Reputation: 9102

I tested the following and works:

br.select_form(nr=0)
for field_name in br.form.controls:
    print field_name

that will give you a clue of the name of the field you need to fill out, it will be on a parentheses like the following:

<HiddenControl(submit_hidden=submit_hidden) (readonly)>
<TextControl(user_name=)>
<PasswordControl(user_password=)>
<SubmitControl(submit=Login) (readonly)>

in this case the fields are user_name and user_password

this is what worked for me, but as I told you the Download link comes in Javascript and mechanize does not support it, you will need something like WATIR which is for ruby.

   browser.select_form(nr=0)

   for field in browser.form.controls:
       field._value = "http://www.youtube.com/watch?v=ARz8ddGIZIA"
       break

   browser.submit()
   response = browser.response().read()

Upvotes: 1

Related Questions