gpt4 book ai didi

Python, Mechanize - 按名称查找表格的问题

转载 作者:太空狗 更新时间:2023-10-30 02:22:59 25 4
gpt4 key购买 nike

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()

问题在于:

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

找不到。

---------------------------
Error
---------------------------
ControlNotFoundError: no control matching name 'ctl00$ctl00$CPContent$CPMain$ddlSkill1'
---------------------------
OK
---------------------------

最佳答案

您可以使用 browser.forms() 迭代器检查哪些表单可用。要找出 Python 解释器中可用的表单,只需执行以下操作:

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

关于Python, Mechanize - 按名称查找表格的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7268886/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com