Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- MySQL
- wol
- mongodb readonly
- IOCP 서버
- mongodb pss
- 윈도우10 Wake On Lan
- docker
- .netCore Install
- Volume Mount
- VirtualBox Ubuntu
- Winsock
- Ubuntu VirtualBox
- .dotnet Core 3.1 Install
- docker desktop
- Ubuntu Server VirtualBox
- IOCP
- Wake On Lan
- ubuntu .net Core
- 닷넷코어
- mongo docker
- 윈도우10 WOL
- DockerDesktop
- 우분투서버가상머신
- dotnet Core
- 도커마운트
- IOCP 클라이언트
- DockerWindows
- .netCore3.1
- DockerVolume
- Docker오류
Archives
- Today
- Total
;
php 웹페이지 파싱! (웹페이지 긁어오기) 본문
반응형
함수 코드 :
function parsing_data($url, $data) { $agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.152 Safari/537.36'; $curlsession = curl_init (); curl_setopt ($curlsession, CURLOPT_URL, $url); // 파싱 주소 url //curl_setopt ($curlsession, CURLOPT_SSL_VERIFYPEER, FALSE); // 인증서 체크같은데 true 시 안되는 경우가 많다. //curl_setopt ($curlsession, CURLOPT_SSLVERSION,3); // SSL 버젼 (https 접속시에 필요) curl_setopt ($curlsession, CURLOPT_HEADER, 0); curl_setopt ($curlsession, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($curlsession, CURLOPT_POST, 1); // POST = 1, GET = 0 curl_setopt ($curlsession, CURLOPT_POSTFIELDS, "".$data.""); // POST 일경우 data 값을 받아 넣을수 ㅆ다.이 curl_setopt ($curlsession, CURLOPT_USERAGENT, $agent); curl_setopt ($curlsession, CURLOPT_REFERER, "http://windowshyun.tistory.com"); // 일부 사이트의 경우 referer 을 확인할 수 있다. curl_setopt ($curlsession, CURLOPT_TIMEOUT, 120); // 해당 웹사이트가 오래걸릴수 있으므로 2분동안 타임아웃 대기 $buffer = curl_exec ($curlsession); $cinfo = curl_getinfo($curlsession); curl_close($curlsession); if ($cinfo['http_code'] != 200){ return $cinfo['http_code']; } return $buffer; }사용 예제 :
function parsing_data($url, $data) { $agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.152 Safari/537.36'; $curlsession = curl_init (); curl_setopt ($curlsession, CURLOPT_URL, $url); // 파싱 주소 url //curl_setopt ($curlsession, CURLOPT_SSL_VERIFYPEER, FALSE); // 인증서 체크같은데 true 시 안되는 경우가 많다. //curl_setopt ($curlsession, CURLOPT_SSLVERSION,3); // SSL 버젼 (https 접속시에 필요) curl_setopt ($curlsession, CURLOPT_HEADER, 0); curl_setopt ($curlsession, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($curlsession, CURLOPT_POST, 0); // POST = 1, GET = 0 curl_setopt ($curlsession, CURLOPT_POSTFIELDS, "".$data.""); // POST 일경우 data 값을 받아 넣을수 ㅆ다.이 curl_setopt ($curlsession, CURLOPT_USERAGENT, $agent); curl_setopt ($curlsession, CURLOPT_REFERER, "http://windowshyun.tistory.com"); // 일부 사이트의 경우 referer 을 확인할 수 있다. curl_setopt ($curlsession, CURLOPT_TIMEOUT, 120); // 해당 웹사이트가 오래걸릴수 있으므로 2분동안 타임아웃 대기 $buffer = curl_exec ($curlsession); $cinfo = curl_getinfo($curlsession); curl_close($curlsession); if ($cinfo['http_code'] != 200){ return $cinfo['http_code']; } return $buffer; } $content = parsing_data("http://windowshyun.tistory.com", ""); echo $content;
사용 결과 :
실제 웹서버에 "test.php" 파일을 만들고 직접 테스트를 한 경우
test.php에서 http://windowshyun.tistory.com 페이지를 그대로 가지고 오게된다.
파싱을 하지 않고 사이트 그대로를 가져오기 때문에, 실제 사이트의 데이터와 똑같이 출력이 된다.
반응형
'PHP' 카테고리의 다른 글
php 클라이언트 맥(MAC)주소 가져오기 (0) | 2017.05.31 |
---|
Comments