gpt4 book ai didi

Python mechanize 忽略 HTML 中的表单输入

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

得到我的小 Mechanize 代码:

br.open('http://tumblr.com/customize'); 
print br.response().read()
print br.form['edit_tumblelog[cname]'] # there definitely is edit_tumblelog
# and br.form['edit_tumblelog[enable_cname]'] works fine

输出:

...
<br/>
<input type="text" class="text_field" style="width:275px; min-width:0px;
margin:6px 0px; border:solid 1px #d2d2d2;
"
name="cname" id="cname"
onchange="form_changed = true;"
value="blog.yay.com"
/>
...
Traceback (most recent call last):
File "/tmp/temp_textmate.W6p5gh", line 51, in <module>
print br.form['edit_tumblelog[cname]']
File "/Library/Python/2.6/site-packages/ClientForm-0.2.10-py2.6.egg/ClientForm.py", line 2891, in __getitem__
File "/Library/Python/2.6/site-packages/ClientForm-0.2.10-py2.6.egg/ClientForm.py", line 3222, in find_control
File "/Library/Python/2.6/site-packages/ClientForm-0.2.10-py2.6.egg/ClientForm.py", line 3306, in _find_control
ClientForm.ControlNotFoundError: no control matching name 'edit_tumblelog[cname]'

我做错了什么?

最佳答案

发现问题。这是 Mechanize HTML 解析器中的一个错误,它在 <br/> 出现后以某种方式忽略了下一个标签。注意 <br />工作正常。我的解决方案是手动替换那些:

response = br.response()
response.set_data(response.get_data().replace("<br/>", "<br />")) #Python mechanize is broken, fixing it.
br.set_response(response)

显然更好的解决方案是 re.sub() /> 之前没有空格的所有标签.

关于Python mechanize 忽略 HTML 中的表单输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2394420/

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