开发者

Python, mechanize - problem with finding form by name

import urllib
import cookielib
import mechanize

url = "http://hattrick.org/World/Transfers/"

cookie = cookielib.CookieJar()
browser = mechanize.Browser()

browser.set_cookiejar(cookie)
browser.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)

browser.open(url)
browser.select_form(name="aspnetForm")
browser.form['ctl00$ctl00$CPContent$ucSubMenu$ucLogin$txtUserName'] = 'login8192'
browser.form['ctl00$ctl00$CPContent$ucSubMenu$ucLogin$txtPassword'] = '8192login'

response = browser.submit()

browser.select_form(name="aspnetForm")


#<select name="ctl00$ctl00$CPContent$CPMain$ddlSkill1" id="ctl00_ctl00_CPContent_CPMain_ddlSkill1" class="skillDropDown" style="width:120px;">

#control=browser.form.find_control("ctl00$ctl00$CPContent$CPMain$ddlSkill1")# <--- here is the problem

#<select name="ctl00$ctl00$CPContent$CPMain$ddlSkill1Min" id="ctl00_ctl00_CPContent_CPMain_ddlSkill1Min"
#onchange="primaryMinSelected('ctl00_ctl00_CPContent_CPMain_ddlSkill1Min', 'ctl00_ctl00_CPContent_CPMain_ddlSkill1Max');"
#onkeyup="primaryMinSelected('ctl00_ctl00_CPContent_CPMain_ddlSkill1Min', 'ctl00_ctl00_CPContent_CPMain_ddlSkill1Max');" style="width:120px;">

control=browser.form.find_control("ctl00$ctl00$CPContent$CPMain$ddlSkill1Min")
#this works fine

response=browser.submit()

Problem is that:

control=browser.form.find_control("ctl00$ctl00$CPContent$CPMain$ddlSkill1")

cannot be find.

---------------------------
Error
----------------开发者_如何转开发-----------
ControlNotFoundError: no control matching name 'ctl00$ctl00$CPContent$CPMain$ddlSkill1'
---------------------------
OK   
---------------------------


You can check what forms are available by using the browser.forms() iterator. To find out what forms are available in a Python interpreter, just do:

>>> print [form for form in browser.forms()][0]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜