gpt4 book ai didi

python - 如何在 Mechanize/Python 中设置隐藏形式的值?

转载 作者:太空狗 更新时间:2023-10-29 20:34:11 29 4
gpt4 key购买 nike

我正在抓取一个使用隐藏表单作为对抗我正在尝试做的事情的手段的网站。这种形式:

<input style="width: 2px; height: 25px" type="hidden" size="1" name="TestJavaScript" /> 

是罪魁祸首。表单期望此输入的值将由稍后执行的一些 JavaScript 设置为“OK”:

function doSignOn() {
window.document.tether.method = "POST";
window.document.tether.action = "https://missionlink.missionfcu.org/MFCU/login.aspx";
window.document.tether.TestJavaScript.value = "OK";

if (window.document.tether.user.value.length < 1) {
alert("Please enter your Member Number.");
return;
}

if (window.document.tether.PIN.value.length < 1) {
alert("Please enter your Password.");
return;
}

// If we're in the service interruption or notice window, put up an alert.
if (now <= interruption_end) {
if (now >= notice_begin) {
alert(prewarn_alert+'\n\nThank you.');
}
}
window.document.tether.submit();
}

聪明。我正在使用 mechanize 抓取页面,如何设置此表单项的值?当我在 Python 中打印 form 对象时,它是这样的:

<tether POST https://missionlink.missionfcu.org/MFCU/login.aspx application/x-www-form-urlencoded
<TextControl(user=)>
<PasswordControl(PIN=)>
<HiddenControl(TestJavaScript=) (readonly)>
<SelectControl(signonDest=[*My Default Destination, Accounts.Activity, Accounts.Summary, Transfers.AddTransfer, SelfService.SelfService])>
>

因为它显示为“只读”,所以我不能修改它,否则它会抛出异常。当然有解决方法,对吗?有什么想法吗?

最佳答案

已发布elsewhere (即在 mechanize 库的 FAQ 页面上):

form.find_control("foo").readonly = False # allow changing .value of control foo 
form.set_all_readonly(False) # allow changing the .value of all controls

关于python - 如何在 Mechanize/Python 中设置隐藏形式的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5592088/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com