中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

python登陸網(wǎng)頁并處理網(wǎng)站session和cookie

2018-07-20    來源:open-open

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用

這是一個python通過urllib直接登陸網(wǎng)站,并處理網(wǎng)站的session和cookie

import cookielib, urllib, urllib2
 
login = 'ismellbacon123@yahoo.com'
password = 'login'
 
# Enable cookie support for urllib2
cookiejar = cookielib.CookieJar()
urlOpener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
 
# Send login/password to the site and get the session cookie
values = {'login':login, 'password':password }
data = urllib.urlencode(values)
request = urllib2.Request("http://www.imdb.com/register/login", data)
url = urlOpener.open(request)  # Our cookiejar automatically receives the cookies
page = url.read(500000)
 
# Make sure we are logged in by checking the presence of the cookie "id".
# (which is the cookie containing the session identifier.)
if not 'id' in [cookie.name for cookie in cookiejar]:
    raise ValueError, "Login failed with login=%s, password=%s" % (login,password)
 
print "We are logged in !"
 
# Make another request with our session cookie
# (Our urlOpener automatically uses cookies from our cookiejar)
url = urlOpener.open('http://imdb.com/find?s=all&q=grave')
page = url.read(200000)

標(biāo)簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:Java圖片居中裁剪代碼

下一篇: IOS之同步請求、異步請求、GET請求、POST請求