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:
<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:
<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.
Hold in temp:
postad.find("input",{"name":"postal"})["value"] = "29201"
Put to postad:
postad["key or position"] = "29201"
Example List inside 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With