gpt4 book ai didi

Python Mechanize 说现有控件不存在

转载 作者:太空宇宙 更新时间:2023-11-04 06:04:21 27 4
gpt4 key购买 nike

我正在尝试用 python 抓取受密码保护的网站。我的代码如下:

import mechanize
import cookielib
from BeautifulSoup import BeautifulSoup

br = mechanize.Browser()

cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)

br.set_handle_equiv(True)
br.set_handle_gzip(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)

br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)

br.addheaders = [('User-agent', 'Chrome')]

br.open('https://monitor1.returnpath.net/login.php')

for f in br.forms():
print f

br.select_form(nr=1)

br.form['email'] = 'email'
br.form['password'] = 'password'

for 循环返回这个:

<form1 POST https://monitor1.returnpath.net/login.php application/x-www-form-urlencoded
<TextControl(email=)>
<PasswordControl(password=)>
<CheckboxControl(remember=[1])>
<SubmitControl(Submit=Sign In) (readonly)>>
<GET http://now.eloqua.com/e/f2.aspx application/x-www-form-urlencoded
<TextControl(e=)>
<HiddenControl(lang=NA) (readonly)>
<HiddenControl(elqSiteID=841) (readonly)>
<HiddenControl(elqFormName=nLRegFooter-1347904420246) (readonly)>
<SubmitControl(<None>=Sign Me Up) (readonly)>
<SubmitButtonControl(<None>=) (readonly)>>
<POST https://monitor1.returnpath.net/send_feedback.php application/x-www-form-urlencoded
<HiddenControl(size=) (readonly)>
<HiddenControl(nps=) (readonly)>
<TextareaControl(desc=)>
<IgnoreControl(<None>=<None>)>
<IgnoreControl(<None>=<None>)>
<IgnoreControl(<None>=<None>)>
<IgnoreControl(<None>=<None>)>
<IgnoreControl(<None>=<None>)>
<IgnoreControl(<None>=<None>)>
<IgnoreControl(<None>=<None>)>
<IgnoreControl(<None>=<None>)>
<IgnoreControl(<None>=<None>)>
<IgnoreControl(<None>=<None>)>
<IgnoreControl(<None>=<None>)>>

还有这个错误:

mechanize._form.ControlNotFoundError: no control matching name 'email'

输出表明找到了“电子邮件”,所以我不确定为什么它说没有与之匹配的控件?

最佳答案

它是零索引的。试试下面的代码:

br.select_form(nr=0)

关于Python Mechanize 说现有控件不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23089100/

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