Naf*_*Kay 8 python screen-scraping mechanize
我正在抓一个使用隐藏形式的网站,作为对抗我正在尝试的对策的手段.这种形式:
<input style="width: 2px; height: 25px" type="hidden" size="1" name="TestJavaScript" />
Run Code Online (Sandbox Code Playgroud)
是罪魁祸首.该表单期望稍后在该行执行的某些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();
}
Run Code Online (Sandbox Code Playgroud)
聪明.我正在使用mechanize来抓取页面,我该如何设置此表单项的值?当我form用Python 打印对象时,它的外观如下:
<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])>
>
Run Code Online (Sandbox Code Playgroud)
因为它显示为"只读",我无法修改它,否则它会引发异常.当然有一个解决方法,对吧?有任何想法吗?
Naf*_*Kay 27
正如在其他地方发布的那样(即在机械化库的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
Run Code Online (Sandbox Code Playgroud)