xmlhttprequest - How to simulate a AJAX call (XHR) with python and mechanize -


i working on project online homework automatically. able login, finding exercises , filling form using mechanize. discovered submit button trigger javascript function , searched solution. lot of answers consist of 'simulating xhr'. none of them talked details. don't know if screen cap helps. http://i.stack.imgur.com/0g83g.png thanks

if want evaluate javascript, i'd recommend using selenium. open browser can send text python.

first, install selenium: https://pypi.python.org/pypi/selenium

then download chrome driver here: https://code.google.com/p/chromedriver/downloads/list

put binary in same folder python script you're writing. (or add path or whatever, more information here: https://code.google.com/p/selenium/wiki/chromedriver)

afterwards following example should work:

from selenium import webdriver selenium.webdriver.common.keys import keys  driver = webdriver.chrome() driver.get("http://www.python.org") assert "python" in driver.title elem = driver.find_element_by_name("q") elem.send_keys("selenium") elem.send_keys(keys.return) assert "google" in driver.title driver.close() 

more information here (the example there)


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -