我正在尝试使用 Python 登录网站。
我有以下代码,当我登录网站时它确实有效。
import ClientCookie, ClientForm
import urllib, urllib2, cookielib
from BeautifulSoup import BeautifulSoup
cookies = ClientCookie.MozillaCookieJar()
fp = ClientCookie.urlopen("http://www.renrendai.com/loginPage.action?error=false")
forms = ClientForm.ParseResponse(fp)
fp.close()
form = forms[0]
form["j_username"] = "userid"
form["j_password"] = "password"
fp = ClientCookie.urlopen(form.click())
fp.close()
userHomePage_href = "http://www.renrendai.com/lend/userHomePage.action?userId=114590"
userHomePage_doc = ClientCookie.urlopen(userHomePage_href)
userHomePage_soup = BeautifulSoup(userHomePage_doc,fromEncoding="gb18030")
但是如果我用它来登录另一个网站,它就不起作用。
我有这个网站的来源:
<input name="txtUserName" type="text" value="tinkei" id="txtUserName" class="lsls" onfocus="changeborder(this)" onblur="changeborder2(this)" style="height:26px;width:280px;border-width:1px; border-color:LightGray;" />
<input name="txtPassword" type="password" maxlength="50" id="txtPassword" onfocus="changeborder(this)" onblur="changeborder2(this)" style="height:26px;width:280px;border-width:1px; border-color:LightGray;" />
<input type="image" name="btnLogin" id="btnLogin" src="http://static.ppdai.com/skin/images/login_n_button.gif" alt="登录" style="border-width:0px;" />
是因为'btnLogin'的值吗?