2011-01-31 10 views
0

폼 기반 인증을 위해 Kent's Korner 코드를 읽으려고합니다. 적어도 내가 읽으려고하는 웹 사이트는 폼 기반 인증이라고 들었습니다.Python을 사용한 폼 기반 인증

하지만 로그인 페이지를 지나갈 수없는 것 같습니다. 내가 사용하는 코드는

Import urllib, urllib2, cookielib, string 

# configure an opener that will handle cookies 
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) 
urllib2.install_opener(opener) 

# use the opener to POST to the login form and the protected page 
params = urllib.urlencode(dict(username='user', password='stuff')) 
f = opener.open('http://www.hammernutrition.com/forums/memberlist.php?mode=viewprofile&u=1323', params) 
data = f.read() 
f.close() 
f = opener.open('http://www.hammernutrition.com/forums/memberlist.php?mode=viewprofile&u=1323') 
data = f.read() 
f.close() 
+0

아마도 제출 버튼 클릭을 시뮬레이트해야합니다. – Marco

+0

파이썬에서 제출 버튼을 시뮬레이트하는 방법을 알고 있습니까? – gciriani

답변

3

당신은 mechanize (python-mechanize라고 데비안/우분투 패키지)와 너무 자원을 사용하지 않고 파이썬에서 웹 브라우저를 시뮬레이션 할 수 있습니다. 웹 브라우저가하는 것처럼 쿠키와 제출 양식을 모두 처리합니다. 하나의 좋은 예가 Python Dropbox Uploader 스크립트입니다.이 스크립트는 필요에 맞게 변형 할 수 있습니다.