Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
更改an的值<;输入>;使用Python不带类型的标记_Python_Html_Beautifulsoup - Fatal编程技术网

更改an的值<;输入>;使用Python不带类型的标记

更改an的值<;输入>;使用Python不带类型的标记,python,html,beautifulsoup,Python,Html,Beautifulsoup,我正在使用Python3和Mechanize(它使用BeautifulSoup)来填写Web表单,但它只填充了一个字段。讨论中的字段与其他字段的唯一区别在于它没有定义类型。以下是来自页面源的相关片段: <input tabindex="1" id="postal_code" name="postal" size="6" maxlength="15" value="" data-emoji_font="true" style="font-family: 'Bitstream Vera Ser

我正在使用Python3和Mechanize(它使用BeautifulSoup)来填写Web表单,但它只填充了一个字段。讨论中的字段与其他字段的唯一区别在于它没有定义类型。以下是来自页面源的相关片段:

<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;">
我将表单对象命名为
postad
,希望值为
“29201”
,但返回的html页面显示以下内容:

<input id="postal_code" maxlength="15" name="postal" size="6" tabindex="1" value=""></input>

我不知道为什么我不能在这一个字段上获得要更改的值,但我可以填写整个表单。我有什么明显的遗漏吗

结果我确实错过了什么。我发布到的页面有两个邮政编码字段,我填错了。现在工作正常。

保持温度:

postad.find("input",{"name":"postal"})["value"] = "29201"
邮寄:

postad["key or position"] = "29201"
字典内的示例列表:

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

能不能请你详细说明一下你把它放在temp里是什么意思?我还是Python新手,不知道如何使用您的答案。谢谢
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