Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the value of an <input> tag with no type using Python

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.

like image 699
Mynaras Avatar asked Mar 10 '26 12:03

Mynaras


1 Answers

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
like image 58
dsgdfg Avatar answered Mar 13 '26 02:03

dsgdfg