python - Submit without the use of a submit button, Mechanize -


so, started out mechanize, , apparently first thing try on monkey-rhino-level high javascript navigated site.

now thing i'm stuck on submitting form.

normally i'd submit using mechanize built-in submit() function.

import mechanize  browser = mechanize.browser() browser.select_form(name = 'foo') browser.form['bar'] = 'baz' browser.submit() 

this way it'd use submit button that's available in html form.

however, site i'm stuck on had 1 doesn't use html submit buttons... no, they're trying javascript gurus, , submit via javascript.

the usual submit() doesn't seem work this.

so... there way around this?

any appreciated. many thanks!

--[edit]--

the javascript function i'm stuck on:

function foo(bar, baz) {     var qux = document.forms["qux"];      qux.bar.value = bar.split("$").join(":"); qux.baz.value = baz; qux.submit(); } 

what did in python (and doesn't work):

def foo(browser, bar, baz):     qux = browser.select_form("qux")      browser.form[bar] = ":".join(bar.split("$"))     browser.form[baz] = baz     browser.submit() 

three ways:

the first method preferable if form submitted using post/get method, otherwise you'll have resort second , third method.

  1. submitting form manually , check post/get requests, parameters , post url required submit form. popular tools checking headers live http headers extension , firebug extension firefox, , developer tools extension chrome. example of using post/get method:

    import mechanize import urllib  browser = mechanize.browser() #these parameters you've got checking aforementioned tools parameters = {'parameter1' : 'your content',               'parameter2' : 'a constant value',               'parameter3' : 'unique characters might need extract page'              } #encode parameters data = urllib.urlencode(parameters) #submit form (post request). post_url , request type(post/get) same way parameters. browser.open(post_url,data) #submit form (get request) browser.open(post_url + '%s' % data) 
  2. rewrite javascript , execute in python. check out spidermonkey.

  3. emulate full browser. check out selenium , windmill.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -