Pregunta

(I am a newbie in programming)

I am trying to write some Python codes to login a forum, this is webpage: the https://www.artofproblemsolving.com/Forum/ucp.php?mode=login&redirect=/index.php.

And unfortunately I don’t have knowledge in web page source codes. My main question is, how does the form name in the webpage source code looked like?

Because for below codes, row 4, I need the form name of the webpage. However I tried below but not working.

import mechanize
b = mechanize.Browser()
r = b.open("https://www.artofproblemsolving.com/Forum/ucp.php?mode=login&redirect=/index.php")
b.select_form(name="login") 
b.form["login"] = "MYNAME"
b.form["password"] = "MYPASSWORD"
b.submit()

could you please help me? many thanks.

¿Fue útil?

Solución

  1. check how html page is structured, focus on form tag
  2. install FireBug on FireFox browser or use the same built in mechanism if you are on chrome, then with FireBug open go to 'net' tab and check what calls was done to the server when you sumbited the form
  3. install scrapy and go though its tutorial http://doc.scrapy.org/en/latest/intro/tutorial.html, when you feel comfortable enough check how to use scrapy FormRequest http://doc.scrapy.org/en/latest/topics/request-response.html#formrequest-objects

Enjoy!

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top