Testing site: http://testing-ground.scraping.pro/login
Username: admin
Password: 12345
컬 도움말
-u, --user <user:password> Server user and password
웹 양식입니다.
wolf@linux:~$ curl http://testing-ground.scraping.pro/login 2>/dev/null | sed -n '/<form/,/form>/'p
<form action="login?mode=login" method="POST">
<label for="usr">User name:</label>
<input id="usr" name="usr" type="text" placeholder="enter 'admin' here">
<label for="pwd">Password:</label>
<input id="pwd" name="pwd" type="text" placeholder="enter '12345' here">
<input type="submit" value="Login">
</form>
wolf@linux:~$
자격 증명 없이 컬링
wolf@linux:~$ curl http://testing-ground.scraping.pro/login?mode=login 2>/dev/null | egrep 'DENIED|WELCOME'
<li>If you see <span class="success">WELCOME :)</span> then the user credentials were sent, the cookie was passed and HTTP redirect was processed</li>
<li>If you see <span class="error">ACCESS DENIED!</span> then either you entered wrong credentials or they were not sent to the server properly</li>
<h3 class='error'>ACCESS DENIED!</h3><a href='login'><< GO BACK</a></div>
wolf@linux:~$
그러나 자격 증명을 사용한 컬에도 -u admin:12345
동일한 페이지가 표시됩니다.
wolf@linux:~$ curl http://testing-ground.scraping.pro/login?mode=login -u admin:12345 2>/dev/null | egrep 'DENIED|WELCOME'
<li>If you see <span class="success">WELCOME :)</span> then the user credentials were sent, the cookie was passed and HTTP redirect was processed</li>
<li>If you see <span class="error">ACCESS DENIED!</span> then either you entered wrong credentials or they were not sent to the server properly</li>
<h3 class='error'>ACCESS DENIED!</h3><a href='login'><< GO BACK</a></div>
wolf@linux:~$
이 상황에서 컬을 사용하는 올바른 방법은 무엇입니까?
답변1
이것은 작동하는 것 같습니다:
curl -s -L --cookie-jar cookies.txt -d 'usr=admin&pwd=12345' http://testing-ground.scraping.pro/login?mode=login | grep -E 'DENIED|WELCOME'
산출:
<li>If you see <span class="success">WELCOME :)</span> then the user credentials were sent, the cookie was passed and HTTP redirect was processed</li>
<li>If you see <span class="error">ACCESS DENIED!</span> then either you entered wrong credentials or they were not sent to the server properly</li>
<h3 class='success'>WELCOME :)</h3><a href='login'><< GO BACK</a></div>
-s
자동 모드, 진행률 표시줄 없음. 출력은 표준 출력으로 전송됩니다.-L
302 리디렉션 따르기--cookie-jar cookies.txt
쿠키 사용 및 쿠키를 파일에 쓰기cookies.txt
-d 'usr=admin&pwd=12345'
데이터를 공개usr=admin
하고pwd=12345