0

我找不到登录文本框。我可以选择表格,但找不到输入文本。有人能帮我吗?

我正在尝试在http://www.safilonet.safilo.com/上使用此脚本自动登录 谢谢

这是代码和错误消息:

def login(self):
url = self._baseUrl + '/webapp/commerce/safilo/jsp/logon.jsp?lng=E&cpy=10'
self._br.open(url, timeout=30.0)
self._br.select_form(name='logon') 
print 'entrou'
self._br.form['login'] = self._username
self._br.form['password'] = self._password
self._br.submit()

if self._verbose: print 'Login successful.\n'

self.last_logged_in = datetime.datetime.now()

错误信息:

Traceback (most recent call last):
File "E:\billy\Projects\GlassInteg\trunk\src\run.py", line 90, in <module> go()
File "E:\billy\Projects\GlassInteg\trunk\src\run.py", line 39, in go ss = SafiloSupplier(updateBrands=True)
File "E:\billy\Projects\GlassInteg\trunk\src\GlassInteg\Supplier.py", line 283, in __init__
if login: self.login()
File "E:\billy\Projects\GlassInteg\trunk\src\GlassInteg\Supplier.py", line 307, in login
self._br.form['login'] = self._username
File "build\bdist.win32\egg\mechanize\_form.py", line 2780, in __setitem__
File "build\bdist.win32\egg\mechanize\_form.py", line 3101, in find_control
File "build\bdist.win32\egg\mechanize\_form.py", line 3185, in _find_control

mechanize._form.ControlNotFoundError:没有控件匹配名称“登录”

4

1 回答 1

0

根据W3C 验证器,问题似乎是相关页面包含大量无效 HTML

如您所见,mechanize 无法看到“登录”字段:

>>> from mechanize import Browser
>>> br = Browser()
>>> br.open('http://www.safilonet.safilo.com/webapp/commerce/safilo/jsp/logon.jsp?lng=E&cpy=10')
<response_seek_wrapper at 0x1011cc638 whose wrapped object = <closeable_response at 0x1011cc488 whose fp = <socket._fileobject object at 0x1002bd650>>>
>>> br.select_form('logon')
>>> br._pairs()
[('merchant', '23888'), ('lng', 'E'), ('cpy', '10'), ('rightPageURL', 'http://www.safilonet.safilo.com/webapp/commerce/catalog/home.html'), ('password', '')]

如果您可以控制此页面,请尽快修复 HTML。

但是,我假设您没有,所以这里有一些替代选项:

  • 使用硒
  • 尝试使用直接 POST URL 登录(不确定 mechanize 是否支持此功能)
于 2012-10-12T13:48:54.327 回答