天天看點

Python模拟登陸

opener.addheaders = [('User-agent','Mozilla/5.0 (Windows NT 6.3; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0')] #生成Post資料。含有登陸username密碼。

data = urllib.urlencode({"email":user,"password":password}) #以post的方法訪問登陸頁面,訪問之後cookieJar會自定儲存cookie opener.open(login_page,data) #以帶cookie的方式訪問頁面 op=opener.open(url) #讀取頁面源代碼 data= op.read() return data except Exception,e: print "aaaa" #訪問某使用者的個人首頁,事實上這已經實作了人人網的簽到功能。http://blog.chinaunix.net/uid-25979788-id-3481639.html print renrenBrower("http://www.renren.com/home","[email protected]","123456")

分析下:

模拟登陸的時候是post請求。送出表單的位址和人人界面登陸位址是不一樣的,實際是人人界面的登陸位址。也就是wwww.renren.cm.你輸入你的資訊以後它會自己主動跳轉到

form中間就是整個表單

能夠看箭頭指向的地方:

post請求須要username,password,origURL,domain,key_id,captcha_type等。可是後面三個是不變的,不須要加上去。僅僅要前兩個即可

我模拟csdn登陸的時候。五個參數。出去username和paassword以外有兩個參數是動态變化的。我靜态指派,一直登不上,郁悶。記住了假設要動态擷取的一定要動态擷取

好,那我們來看看模拟csdn登陸的話

Python模拟登陸

以下兩個箭頭指向的兩個資料的value是動态變化的。是以假設要模拟登陸的話。須要動态擷取這個值

占時我還不會,貼個我的錯誤代碼,有大神能幫我改改,怎麼動态擷取這兩個值