로그인 권한이 필요한 간단한 html dom을 사용하여 html 페이지를 읽으려고합니다.간단한 HTML DOM을 사용하여 컬링 및 구문 분석 승인
예 : http://example.com/login/은 로그인 페이지이고 http://example.com/page/은 내가 HTML을 구문 분석해야하는 곳입니다.
그래서 저는 컬링을 사용하여 로그인하고 간단한 html dom을 분석합니다.
하지만 내 페이지 로그인 여부를 알지 못합니다. 왜냐하면 말장난의 응답을 로그인 페이지의 내용으로 표시하기 때문입니다!
많은 시간 동안 모든 관련 질문을 검색했지만 잘못된 정보를 찾을 수 없었습니다.
아래
내가 내 페이지의 상단에 응답 무엇을 얻을 내 코드<?php $curlPost['username']="username"; $curlPost['password']="pass"; $curlPost['token']="xxxxxxxxxx"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL , "http://example.com/login/"); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt"); curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt"); $response= curl_exec ($ch); curl_close($ch);
그리고 HTML 페이지 아래
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL , "http://example.com/page/"); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13"); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt"); curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt"); $reponse= curl_exec ($ch); curl_close($ch); echo $response; ?>
를 검색하는 코드입니다 HTTP/1.1 302 Found
날짜 : 2015 년 1 월 28 일 수요일 06:59:44 GMT
서버 : 아파치
X-전원이 기준 : PHP/5.3.3
캐시 제어 : 노 캐시
위치 :/로그인
전송 - 인코딩 : 청크
의 Content-Type : text/html과; 문자셋 = UTF-8
HTTP/1.1 200 OK
날짜 : 2015년 (수) 그리니치 표준시 06시 59분 45초
서버 1월 28일 : 아파치
X-구동 - 기준 : PHP/5.3.3
캐시 - 제어 : no-cache
전송 인코딩 : 청크
내용 유형 : text/html; charset = UTF-8
다음에 로그인 페이지 html 콘텐츠가옵니다.
누구든지 내가 뭘 잘못하고 있는지 조언 해 줄 수 있습니다.
저는 로컬 호스트에서 서버에서 호스팅되는 대상을 실행하고 있습니다.
그리고 "cookies.txt"파일에 어떤 변화도 일어나지 않았습니다.
감사합니다.
cookies.txt의 경로를 /var/www/app/cookies.txt와 같은 절대 경로로 설정하고 적절한 사용 권한을 cookies.txt로 설정해보십시오. 로그인이 성공하면 cookies.txt에 텍스트가 표시 될 수 있습니다. –
서버에 업로드하여 실행하려고했지만 쿠키에는 아무런 변화가 없습니다. p.s : 쿠키에 대해 지정된대로 전체 경로를 따릅니다.txt –