이 코드는 어딘가에 reddit에 대한 stackoverflow에 있습니다. 내가 hackthissite.org에 대한 수정을 시도 :Python : 웹 사이트에 로그인
<form id="loginform" method="post" action="/user/login">
<div id="innerlogin">
<script type="text/javascript">var userclicked=0; var passclicked=0;</script>
<p><input type="text" name="username" class="login" value="" onclick="if(userclicked==0){this.value='';userclicked=1;};" title="Username" /></p>
<p><input type="password" name="password" class="login" value="" onclick="if(passclicked==0){this.value='';passclicked=1;};" title="Password" /></p>
<p><input type="submit" value="Login" name="btn_submit" class="submit-button" /></p>
</div>
</form>
내가 얻는 응답 : 나는 페이로드 권리를 가지고 말할 수있는 지금까지
import urllib2
import urllib
import cookielib
# Store the cookies and create an opener to hold them
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
# Add our headers
opener.addheaders = [('User-agent', 'Tester')]
# Install the opener, changes the global opener to the one we just made
urllib2.install_opener(opener)
# URL for authentification
auth_url = 'https://www.hackthissite.org/user/login'
# Parameters to send
payload = {
'username': 'myUser',
'password': 'myPass',
'btn_submit': 'Login'
}
# Encode payload
data = urllib.urlencode(payload)
# Build request object (supplying 'data' makes it a POST)
req = urllib2.Request(auth_url, data)
# Make request and store in resp
resp = urllib2.urlopen(req)
print resp
을,이 hackthissite.org에 로그인 폼이다 서버에서 :
<addinfourl at 36515712 whose fp = <socket._fileobject object at 0x022D3DB0>>
어떻게 사이트에 로그인 할 수 있습니까? 이 경우 서버 응답이 의미하는 것은 무엇입니까? (AddInfoUrl?)
감사합니다. 내가 살펴볼 것입니다! 술어 = lambda f : f.attrs.get ('조치') == '/ user/login' 조치가있는 br에서 양식을 선택한다는 것을 알고 있습니다 =/user/login "하지만 술어 = lambda f는 무엇을 의미합니까? – Juicy
확실한 것, 업데이트 확인 – Claudiu
남자 감사합니다! – Juicy