網頁自動登陸 (Python)
雖然真的能登陸成功,不過實在看不太懂
#coding=utf-8
import urllib,urllib2,cookielib
import time
def pop2():
url_login = 'http://diy.ic.net.cn/login/'
body = (
('username','wwwwww'),
('password','wwwwww'))
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookielib.CookieJar()))
#opener.addheaders = [('User-agent','Opera/10.00')]
urllib2.install_opener(opener)
req = urllib2.Request(url_login,urllib.urlencode(body))
u = urllib2.urlopen(req)
print u.read()
url = 'http://diy.ic.net.cn/admins/'
req = urllib2.Request(url)
print urllib2.urlopen(req).read()
if __name__ == '__main__':
#while True:
pop2()
time.sleep(3)
如有錯誤 歡迎指正