日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

【python】自动登录51cto家园

發布時間:2024/3/13 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【python】自动登录51cto家园 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.


自動登錄:http://home.51cto.com


1、分析:

使用httpfox抓取手動登錄home.51cto.com的過程,過程如下:


點登錄,提交用戶名與密碼到http://home.51cto.com/index.php?s=/Index/doLogin?這個地址,正確后,他會返回的內容包含很多鏈接,如第二個圖片。然后分別get這些鏈接。請求完這些鏈接后,再訪問個人主頁http://home.51cto.com/index.php?s=/Home/index



post成功后服務器返回的內容。



2、思路有了,那么就是寫代碼了。(登錄是使用onepc的帳號,完后后可以返回的html中找到onepc)


登錄代碼參考網上的資料。


import?urllib.request import?urllib.parse import?http.cookiejar import?reposturl='http://home.51cto.com/index.php?s=/Index/doLogin' url='http://home.51cto.com'cookie?=?http.cookiejar.LWPCookieJar() cookie_support?=?urllib.request.HTTPCookieProcessor(cookie) opener?=?urllib.request.build_opener(cookie_support,?urllib.request.HTTPHandler) urllib.request.install_opener(opener)urllib.request.urlopen(url)headers?=?{'User-Agent':'Mozilla/5.0?(Windows?NT?6.1;?WOW64;?rv:30.0)?Gecko/20100101?Firefox/30.0','Referer':'http://home.51cto.com/','Host':'home.51cto.com'}postdata={'email':'hxw168','passwd':'xxxx','reback':''}??#密碼未加密postdata=urllib.parse.urlencode(postdata).encode('utf-8')request=urllib.request.Request(posturl,postdata,headers)response=urllib.request.urlopen(request)html=response.read().decode('utf-8')#print(response.read().decode('utf-8'))#print(html)#這里把post成功后返回的內容中取得各個url,然后分別執行。 r_geturl=re.compile('src="([^"]+)"',re.S) logurllist=r_geturl.findall(html) for?l?in?logurllist:urllib.request.urlopen(l)s=urllib.request.urlopen('http://home.51cto.com/index.php?s=/Home/index')print(s.read().decode('utf-8'))?#這里可以讀取到用戶帳號、短信息登錄成功后就可以做別的事了。



轉載于:https://blog.51cto.com/hxw168/1535751

總結

以上是生活随笔為你收集整理的【python】自动登录51cto家园的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。