0
我嘗試訪問HTML表單中的行,在表單的HTML代碼是這樣你如何訪問行中的HTML表單usibg蟒蛇表機械化
</script>
<form name="calendarForm" method="post" action="/ibook/publicLogin.do" onsubmit="return validateForm(this);"><div><input type="hidden" name="org.apache.struts.taglib.html.TOKEN" value="7a6aa28270cc38601c894a05d01b7264"></div>
<input type="hidden" name="apptDetails.apptType" value="PRAP">
<table border="0" cellspacing="1" cellpadding="0" align="center">
<tr>
<td nowrap="nowrap" width="20%"><div id=id_div1 style="display:''"><FONT color=#ff0000>*</FONT><label for="apptDetails.identifier1">Sponsor's NRIC /<br /> Applicant's FIN</label></div></td>
<td nowrap="nowrap" width="5%">:</td>
<td nowrap="nowrap" width="75%"><div id=id_div3 style="display:''"><input type="text" name="apptDetails.identifier1" maxlength="9" size="15" value="" onblur="javascript:this.value=this.value.toUpperCase();" id="apptDetails.identifier1" style="text-transform: uppercase;" class="txtFill_singleLine"></div></td>
</tr>
IM特林信息添加到行與名稱name="apptDetails.identifier1"
我如何輸入值的行?我不似乎能夠使用傳統的蟒蛇機械化形式選項來訪問HTML行請大家指教
這裏是我的代碼
import cookielib
import urllib2
import mechanize
# Browser
br = mechanize.Browser()
# Enable cookie support for urllib2
cookiejar = cookielib.LWPCookieJar()
br.set_cookiejar(cookiejar)
# Broser options
br.set_handle_equiv(True)
br.set_handle_gzip(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)
# ??
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time = 1)
br.addheaders = [ ('User-agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0'),('Host','eappointment.ica.gov.sg'),('Accept','text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8') ]
# authenticate
br.open('https://eappointment.ica.gov.sg/ibook/gethome.do')
print "forms"
br.select_form(name="calendarForm")
print "forms"
# these two come from the code you posted
# where you would normally put in your username and password
br.find_control(name="apptDetails.apptType").value = ['PRAP']
res = br.submit()
html = br.response().readlines()
file = open("html.txt", "w")
for i in range(0, len(html)):
file.write(html[i])
file.write('\n')
file.close()
br.close()
print "Success!\n"
謝謝你現在就試試,很好的建議 – Adhil 2015-03-13 12:08:45