web scraping - Python mechanize form submitting doesn't work -


I am trying to write a simple bot which will enter my account on a page and then images from other users Will comment on Although I am not able to get the comment form to present the work correctly. The comment form looks like this:

  & lt; Form id = "comment-form" action = "#" onsubmit = "post comment ($ (this). Serialize (), 'image', 117885229227); returned;" & gt; & Lt; Input class = "comment" type = "article" size = "40" name = "comment" id = "comment" /> & Lt; Input type = "hidden" name = "comment obz" value = "9234785" /> & Lt; Input type = "hidden" name = "comment mode" value = "image" /> & Lt; Input type = "hidden" name = "user id" value = "12427" /> & Lt; Input class = "submit" type = "submit" value = "comment" /> & Lt; / Form & gt;   

My code is as follows

  br.select_form (nr = 1) br.form ['comment'] = 'hello' br.submit ()   

The page has two forms and the comment form is second. So I'm sure I have chosen the right form. Anyone can tell that why does not this work?

A javascript code is executed, while the form is being submitted:

  onsubmit = "postcomment ($ (this). Serialize (), 'image', 117885,229227) returned;"   

mechanize simply can not handle it because it is not a browser and does not have a javascript engine.

Potential Solution:

  • A High Level Approach - Use an actual browser through WebDrive and Automated Usage Actions - Send Keys Into an Input, Submit Click on the button etc. Example code:

      selenium import web driver driver = webdriver.firefox () dirver.get ('my_url_here') comment = driver.find_element_by_id ('comment') comment.send_keys ('Hello') comment.submit () # This will get an attached form and submit it    
  • The request for research (s) is being sent to the server, while the form submitted is being removed. After this, for example, automate the request used.

    Hope that helps.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -