尝试在 Python 中使用 mechanize 时,我被卡住了,因为我尝试提交的字段没有名称。
在机械化教程上,据说:
br.select_form(name="order")
# Browser passes through unknown attributes (including methods)
# to the selected HTMLForm.
br["cheeses"] = ["mozzarella", "caerphilly"] # (the method here is __setitem__)
这很好,但在我的情况下,控件没有名称。这是我运行的代码以确保:
resp = br.open("http://www.facebook.com/find-friends/browser/")
forms = ParseResponse(resp)
form = forms[2] # I know I have to select form 2
for control in forms[0].controls:
print control.name, control.type
这是我得到的(部分):
fb_dtsg hidden
friends_ids[] checkbox
None button
None hidden
None text
hometown_ids[] checkbox
None button
None hidden
None text
city_ids[] checkbox
None button
None hidden
None text
highschool_ids[] checkbox
None button
None hidden
None text
college_ids[] checkbox
所以我被困在这里,因为我无法应用教程中的示例(我想做的是:
br['hometown'] = 'some town'
有人有线索吗?
谢谢