I'm using Python 3 with Mechanize, which uses BeautifulSoup, to fill out a webform, but it fills all fields but one. The field in question is only different from the others in that it has no type defined. Here is the relevant snippet from the source of the page:
我正在使用带有BeautifulSoup的Python 3来填充webform,但它填充了所有字段,但只填写了一个。所讨论的字段仅与其他字段不同,因为它没有定义类型。以下是来自页面源的相关代码段:
<input tabindex="1" id="postal_code" name="postal" size="6" maxlength="15" value="" data-emoji_font="true" style="font-family: 'Bitstream Vera Serif', 'Times New Roman', serif, 'Segoe UI Emoji', 'Segoe UI Symbol', Symbola, EmojiSymbols !important;">
The line in the code is as follows:
代码中的行如下:
postad.find("input",{"name":"postal"})["value"] = "29201"
I named the form object postad
and I want the value to be "29201"
, but instead, the returned html page shows this:
我将表单对象命名为postad,我希望该值为“29201”,但是返回的html页面显示了以下内容:
<input id="postal_code" maxlength="15" name="postal" size="6" tabindex="1" value=""></input>
I'm at a loss as to why I can't get the value to change on this one field, but I'm able to fill out the entire form. Is there something obvious I'm missing?
我不知道为什么我无法在这一领域获得改变的价值,但我能够填写整个表格。有什么明显的东西我不见了吗?
Turns out I did miss something. The page I was posting to had two fields for the postal code, and I filled out the wrong one. Now it works fine.
事实证明我确实错过了什么。我发布的页面有两个邮政编码字段,我填写了错误的字段。现在它工作正常。
1 个解决方案
#1
2
Hold in temp:
保持温度:
postad.find("input",{"name":"postal"})["value"] = "29201"
Put to postad:
投入邮件:
postad["key or position"] = "29201"
Example List inside Dictionary:
Dictionary中的示例列表:
a = [{"name":"a","value":""},{"name","b","value":"s"}]
for e in a:
if e["name"] == "a":
d = e
d["value"] = "new_value"
a[a.index(e)] = d #My answer
break
#1
2
Hold in temp:
保持温度:
postad.find("input",{"name":"postal"})["value"] = "29201"
Put to postad:
投入邮件:
postad["key or position"] = "29201"
Example List inside Dictionary:
Dictionary中的示例列表:
a = [{"name":"a","value":""},{"name","b","value":"s"}]
for e in a:
if e["name"] == "a":
d = e
d["value"] = "new_value"
a[a.index(e)] = d #My answer
break