我在尋找需要傳遞給特定網站並提交的表單數據。下面是我需要模擬的html(僅表格)。我一直在這個工作幾個小時,但似乎無法得到任何工作。我希望這可以在Google App Engine中工作。你能幫忙的話,我會很高興。通過Python獲取表單數據
<form method="post" action="/member/index.bv">
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td align="left">
<h3>member login</h3><input type="hidden" name="submit" value="login" /><br />
</td>
</tr>
<tr>
<td align="left" style="color: #8b6c46;">
email:<br />
<input type="text" name="email" style="width: 140px;" />
</td>
</tr>
<tr>
<td align="left" style="color: #8b6c46;">
password:<br />
<input type="password" name="password" style="width: 140px;" />
</td>
</t>
<tr>
<td>
<input type="image" class="formElementImageButton" src="/resources/default/images/btnLogin.gif" style="width: 46px; height: 17px;" />
</td>
</tr>
<tr>
<td align="left">
<div style="line-height: 1.5em;">
<a href="/join/" style="color: #8b6c46; font-weight: bold; text-decoration: underline; ">join</a><br />
<a href="/member/forgot/" style="color: #8b6c46; font-weight: bold; text-decoration: underline;">forgot password?</a><input type="hidden" name="lastplace" value="%2F"><br />
having trouble logging on, <a href="/cookieProblems.bv">click here</a> for help
</div>
</td>
</tr>
</table>
</form>
當前我試圖使用此代碼來訪問它,但它不工作。我對此很新,所以也許我只是想念它。
import urllib2, urllib
url = 'http://blah.com/member/index.bv'
values = {'email' : '[email protected]',
'password' : 'somepassword'}
data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
the_page = response.read()
我剛試過,沒有工作。我不確定index.bv文件是什麼。你認爲這與它有關嗎? – shawn
我懷疑index.bv是否是它。你看過你的網頁瀏覽器的調試功能嗎?例如,Firebug可以顯示發送給服務器的內容。 –