html - Input into site using Mechanize (Python) -
i'm trying make dictionary program using dictionary.com source can't find name of search box in source code
from mechanize import browser inp = raw_input("enter word: ") word = (inp) search_page = "http://dictionary.reference.com/" browser = browser() browser.open( search_page ) browser.select_form( nr=0 ) browser['name of search form'] = word browser.submit()
can me make work or me find name of search bar in html source?
you can through forms method browser.forms(). each of these forms has variable called controls, list of controls in form. each control in list has "name" variable. can use these names index browser, know.
from mechanize import browser inp = raw_input("enter word: ") word = (inp) search_page = "http://dictionary.reference.com/" browser = browser() browser.open( search_page ) form = list(browser.forms())[0] #the first form print form names = map(lambda n: n.name, form.controls) print names browser.select_form( nr=0 ) browser[names[0]] = word txt = browser.submit().read() #txt has html dictionary.reference.com
Comments
Post a Comment