5월 2025 | ||||||
---|---|---|---|---|---|---|
일 | 월 | 화 | 수 | 목 | 금 | 토 |
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 |
실패한 사람이 다시 일어나지 못하는 것은 그 마음이 교만한 까닭이다. 성공한 사람이 그 성공을 유지하지 못하는 것도 역시 교만한 까닭이다. -불경
cURL (Client URL Library Functions)
cURL로 가능한 일
cURL, Client URL Library Functions
[예제1 : POST방식으로 데이터 전송(simple)]
<?
$post_data = array(
"name" => "홍길동",
"birthday" => "1980-08-20"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, http://www.example.com);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_exec($ch);
?>
[예제2: POST방식으로 데이터 전송(function)]
<?
function fetch_page($url,$param,$cookies,$referer_url){
if(strlen(trim($referer_url)) == 0) $referer_url= $url;
$curlsession = curl_init ();
curl_setopt ($curlsession, CURLOPT_URL, \"$url\");
curl_setopt ($curlsession, CURLOPT_POST, 1);
curl_setopt ($curlsession, CURLOPT_POSTFIELDS, \"$param\");
curl_setopt ($curlsession, CURLOPT_POSTFIELDSIZE, 0);
curl_setopt ($curlsession, CURLOPT_TIMEOUT, 60);
if($cookies && $cookies!=\"\"){
curl_setopt ($curlsession, CURLOPT_COOKIE, \"$cookies\");
}
curl_setopt ($curlsession, CURLOPT_HEADER, 1); //헤더값을 가져오기위해 사용합니다. 쿠키를 가져오려고요.
curl_setopt ($curlsession, CURLOPT_USERAGENT, \"Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)\");
curl_setopt ($curlsession, CURLOPT_REFERER, \"$referer_url\");
ob_start();
$res = curl_exec ($curlsession);
$buffer = ob_get_contents();
ob_end_clean();
if (!$buffer) {
$returnVal = \"Curl Fetch Error : \".curl_error($curlsession);
}else{
$returnVal = $buffer;
}
curl_close($curlsession);
return $returnVal;
}
?>
[예제3 : 파일 전송]
<?
$post_data['data[0]'] = "@image/img_01.jpg";
$post_data['data[0]'] = "@image/img_02.jpg";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, http://www.example.com/upload.php);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$postResult = curl_exec($ch);
?>
[예제4 : https 접속]
<?
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL,"https://www.test.com"); //접속할 URL 주소
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // 인증서 체크같은데 true 시 안되는 경우가 많다.
// default 값이 true 이기때문에 이부분을 조심 (https 접속시에 필요)
curl_setopt ($ch, CURLOPT_SSLVERSION,3); // SSL 버젼 (https 접속시에 필요)
curl_setopt ($ch, CURLOPT_HEADER, 0); // 헤더 출력 여부
curl_setopt ($ch, CURLOPT_POST, 1); // Post Get 접속 여부
curl_setopt ($ch, CURLOPT_POSTFIELDS, "var1=str1&var2=str2"); // Post 값 Get 방식처럼적는다.
curl_setopt ($ch, CURLOPT_TIMEOUT, 30); // TimeOut 값
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); // 결과값을 받을것인지
$result = curl_exec ($ch);
curl_close ($ch);
echo $result;
?>
[예제5 : curl을 이용한 Gmail 로그인]
$src = "https://".$gmailId.":".$gmailPw."@mail.google.com/mail/feed/atom";
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, 'My Agent Name');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
$res = curl_exec($ch);
curl_close($ch);
/** 결과는 Atom xml 형식이다. DOM 또는 xml 파싱 function을 이용해서 파싱하면 됩니다. **/
echo $res;
?>
[예제6 : cURL을 이용한 웹페이지 가져오기]
<?php
function get_content($url) {
$agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)';
$curlsession = curl_init ();
curl_setopt ($curlsession, CURLOPT_URL, $url);
curl_setopt ($curlsession, CURLOPT_HEADER, 0);
curl_setopt ($curlsession, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($curlsession, CURLOPT_POST, 0);
curl_setopt ($curlsession, CURLOPT_USERAGENT, $agent);
curl_setopt ($curlsession, CURLOPT_REFERER, "");
curl_setopt ($curlsession, CURLOPT_TIMEOUT, 3);
$buffer = curl_exec ($curlsession);
$cinfo = curl_getinfo($curlsession);
curl_close($curlsession);
if ($cinfo['http_code'] != 200)
{
return "";
}
return $buffer;
}
?>
curl_close
Error Code
There exists a bunch of different error codes and their corresponding error messages that may appear during bad conditions. At the time of this writing, the exit codes are:
1 - Unsupported protocol. This build of curl has no support for this protocol.
2 - Failed to initialize.
3 - URL malformat. The syntax was not correct.
잘못된 형식의 도메인
5 - Couldn't resolve proxy. The given proxy host could not be resolved.
6 - Couldn't resolve host. The given remote host was not resolved.
해당 도메인을 못찾는다는 뜻
네임서버가 제대로 등록되어 있는지 확인하고 도메인도 정확한지 확인할 것.
7 - Failed to connect to host.
8 - FTP weird server reply. The server sent data curl couldn't parse.
9 - FTP access denied. The server denied login or denied access to the particular resource or directory you wanted to reach. Most often you tried to change to a directory that doesn't exist on the server.
11 - FTP weird PASS reply. Curl couldn't parse the reply sent to the PASS request.
13 - FTP weird PASV reply, Curl couldn't parse the reply sent to the PASV request.
14 - FTP weird 227 format. Curl couldn't parse the 227-line the server sent.
15 - FTP can't get host. Couldn't resolve the host IP we got in the 227-line.
17 - FTP couldn't set binary. Couldn't change transfer method to binary.
18 - Partial file. Only a part of the file was transferred.
19 - FTP couldn't download/access the given file, the RETR (or similar) command failed.
21 - FTP quote error. A quote command returned error from the server.
22 - HTTP page not retrieved. The requested url was not found or returned another error with the HTTP error code being 400 or above. This return code only appears if -f/--fail is used.
23 - Write error. Curl couldn't write data to a local filesystem or similar.
25 - FTP couldn't STOR file. The server denied the STOR operation, used for FTP uploading.
26 - Read error. Various reading problems.
27 - Out of memory. A memory allocation request failed.
28 - Operation timeout. The specified time-out period was reached according to the conditions.
30 - FTP PORT failed. The PORT command failed. Not all FTP servers support the PORT command, try doing a transfer using PASV instead!
31 - FTP couldn't use REST. The REST command failed. This command is used for resumed FTP transfers.
33 - HTTP range error. The range "command" didn't work.
34 - HTTP post error. Internal post-request generation error.
35 - SSL connect error. The SSL handshaking failed.
36 - FTP bad download resume. Couldn't continue an earlier aborted download.
37 - FILE couldn't read file. Failed to open the file. Permissions?
38 - LDAP cannot bind. LDAP bind operation failed.
39 - LDAP search failed.
41 - Function not found. A required LDAP function was not found.
42 - Aborted by callback. An application told curl to abort the operation.
43 - Internal error. A function was called with a bad parameter.
45 - Interface error. A specified outgoing interface could not be used.
47 - Too many redirects. When following redirects, curl hit the maximum amount.
48 - Unknown TELNET option specified.
49 - Malformed telnet option.
51 - The peer's SSL certificate or SSH MD5 fingerprint was not ok
에러 메시지) SSL: certificate subject name 'www.test.co.kr' does not match target host name 'test.co.kr'
해결1) 인증서 발급받은 주소로 호출하거나
해결2) 설정으로 제어
$soapClient->setOpt('curl', CURLOPT_SSL_VERIFYHOST, 0);
52 - The server didn't reply anything, which here is considered an error.
53 - SSL crypto engine not found
54 - Cannot set SSL crypto engine as default
55 - Failed sending network data
56 - Failure in receiving network data
58 - Problem with the local certificate
59 - Couldn't use specified SSL cipher
60 - Peer certificate cannot be authenticated with known CA certificates
인증서 신뢰 검증에 실패한 경우다. (통합인증서, 번들과 관련 있는 듯)
에러 메시지) SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
해결) 신뢰 검증을 하지 않도록 설정.
상호 서버가 신뢰된다면 굳이 신뢰성을 검증하지 않아도 된다.
$soapClient->setOpt('curl', CURLOPT_SSL_VERIFYPEER, 0);
61 - Unrecognized transfer encoding
62 - Invalid LDAP URL
63 - Maximum file size exceeded
64 - Requested FTP SSL level failed
65 - Sending the data requires a rewind that failed
66 - Failed to initialise SSL Engine
67 - User, password or similar was not accepted and curl failed to login
68 - File not found on TFTP server
69 - Permission problem on TFTP server
70 - Out of disk space on TFTP server
71 - Illegal TFTP operation
72 - Unknown TFTP transfer ID
73 - File already exists (TFTP)
74 - No such user (TFTP)
75 - Character conversion failed
76 - Character conversion functions required
77 - Problem with reading the SSL CA cert (path? access rights?)
78 - The resource referenced in the URL does not exist
79 - An unspecified error occurred during the SSH session
80 - Failed to shut down the SSL connection
XX - There will appear more error codes here in future releases. The existing ones are meant to never change
curl_error
curl_init
curl_exec
curl_getinfo
curl_setopt
CURLOPT_FOLLOWLOCATION
TRUE to follow any "Location: " header that the server sends as part of the HTTP header (note this is recursive, PHP will follow as many "Location: " headers that it is sent, unless CURLOPT_MAXREDIRS is set).
FOLLOWLOCATION 옵션 설정. 위치 헤더가 존재하면 따라간다.
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, tru
CURLOPT_HEADER
TRUE to include the header in the output.
헤더 정보를 받기 원한다면 이 옵션을 추가한다.
VALUE : 1 OR true
curl_setopt($ch, CURLOPT_HEADER, false);
CURLOPT_NOBODY
TRUE to exclude the body from the output.
본문의 정보를 받기 원하지 않는다면 이 옵션을 추가한다.
CURLOPT_POST
TRUE to do a regular HTTP POST. This POST is the normal application/x-www-form-urlencoded kind, most commonly used by HTML forms.
전송 메소드를 설정한다.
VALUE : 1-POST, 0-GET
curl_setopt($ch, CURLOPT_POST,1);
CURLOPT_RETURNTRANSFER
TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
REQUEST 에 대한 결과값을 받을 건지 체크
(WRITERUNCTION 콜백을 사용하는 대신, curl_exec 함수을 위한 반환 값으로 원격지 내용을 받는다.)
#Resource ID 형태로 넘어옴 :: 내장 함수 curl_errno 로 체크
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
CURLOPT_SSL_VERIFYPEER
FALSE to stop cURL from verifying the peer's certificate. Alternate certificates to verify against can be specified with the CURLOPT_CAINFO option or a certificate directory can be specified with the CURLOPT_CAPATH option. CURLOPT_SSL_VERIFYHOST may also need to be TRUE or FALSE if CURLOPT_SSL_VERIFYPEER is disabled (it defaults to 2).
인증서 체크같은데 true 시 안되는 경우가 많다.
default 값이 true 이기때문에 이 부분을 조심 (https 접속시에 필요)
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
CURLOPT_PORT
An alternative port number to connect to.
CURLOPT_SSLVERSION
The SSL version (2 or 3) to use. By default PHP will try to determine this itself, although in some cases this must be set manually.
SSL 버젼 (https 접속시에 필요)
curl_setopt ($ch, CURLOPT_SSLVERSION,3);
CURLOPT_TIMEOUT
The maximum number of seconds to allow cURL functions to execute.
REQUEST 에 대한 결과값을 받는 시간타임 설정한다.
curl_setopt($ch, CURLOPT_TIMEOUT,100);
CURLOPT_POSTFIELDS
The full data to post in a HTTP "POST" operation. To post a file, prepend a filename with @ and use the full path.
POST 메소드라면 파라미터 값들을 이 옵션에 정의하면 된다.
curl_setopt($cu, CURLOPT_POSTFIELDS,$vars); // 보낼 데이타 형식은 GET 방식으로 설정
ex) $vars = "arg=$arg1&arg2=$arg2&arg3=$arg3";
CURLOPT_REFERER
The contents of the "Referer: " header to be used in a HTTP request.
리퍼러 정보를 설정
CURLOPT_URL
The URL to fetch. This can also be set when initializing a session with curl_init().
접속할 url정보를 설정
curl_init()에서 url를 설정하면 별도 설정이 필요없다.
curl_setopt($ch, CURLOPT_URL, 'http://www.exsample.com');
CURLOPT_USERAGENT
The contents of the "User-Agent: " header to be used in a HTTP request.
에이전트 정보를 설정
curl_setopt($ch, CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
출처: https://xshine.tistory.com/251 [메모하는습관:티스토리]
2022-08-03 06:36:41
파일 에펨 코리아 크롤링 -> 게시판 번호 -> 내용 및 이미지 저장
1.fmkorea.php 파일 데이터 가져오기
<!-- CURL -> 웹 사이트와 간단한 통신(입출력)을 가능하게 해줌 이것을 응용한 활용법 //에펨 코리아 크롤링 //https://www.fmkorea.com/?document_srl=4857119622 1.메인화면 데이터 best 최상의 값을 가져온다. document_srl=4857119622 2.아이디값을 통해 상세화면으로 이동해서 제목, 컨텐츠 내용을 값을 가져온다. 3.기존에 등록한 내용인지 fmkorea_id= 4857119622 을 통해 검색한다. //신규 데이터라면 4.이미지를 다운로드 한다. 5.이미지를 이지디 호스팅 에 등록한다. 6.그누보드에 저장한 이미지를 삭제한다. 7.데이터를 DB에 저장한다. --> <?php error_reporting( E_ALL ); ini_set( "display_errors", 1 ); include_once("../common.php"); ini_set("allow_url_fopen", 1); header('Content-Type: text/html; charset=UTF-8'); $URL="https://www.fmkorea.com"; $userAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36 Unique/98.7.5806.7"; function getContents($webpage){ //웹페이지 내용 가져오기 $ch=curl_init($webpage); //curl 초기화 curl_setopt($ch, CURLOPT_FAILONERROR, true); //TRUE로 설정 시 HTTP 헤더로 보내는 LOCATION헤더의 내용을 따른다. curl_setopt($ch, CURLOPT_HEADER, 0); // TRUE로 설정 시 헤더의 내용을 출력 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // TRUE로 설정 시 curl_exec()의 반환 값을 문자열로 반환 curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); // 30초내에 서버에서 응답이 없을경우 강제 해제 됨 curl_setopt($ch, CURLOPT_TIMEOUT, 400); //400초 내에 다운로드가 완료되지 않을경우 강제 해제된다. $webcontents=curl_exec($ch); curl_close($ch); return $webcontents; } //앞뒤로 문자열 구분해서 추출 function findStringBetweenAndB($dest, $A, $B) { $firstFindIdx=strpos($dest, $A); $firstFindIdx=$firstFindIdx +strlen($A); $secondFindIdx=strpos($dest, $B, $firstFindIdx); if($secondFindIdx===false){ echo "not found!"; exit(); } $findSearString=trim(substr($dest, $firstFindIdx, $secondFindIdx-$firstFindIdx)); return $findSearString; } $getCrawling =getContents($URL); $dataExtract1 =findStringBetweenAndB($getCrawling, '<li class="li li_best2_pop1 li_best2_hotdeal0">', '</li>'); $regId=findStringBetweenAndB($dataExtract1, 'document_srl=', '"');//아이디 값 가져오기 //https://www.fmkorea.com/index.php?mid=humor&sort_index=pop&order_type=desc&document_srl=4833825191&listStyle=webzine //4833825191 //https://www.fmkorea.com/index.php?document_srl=4833825191 //echo $dataExtract1; => 등록 번호 추출 =>4833825191 $getCrawling = getContents($URL."/index.php?document_srl=".$regId); $title=findStringBetweenAndB($getCrawling, '<span class="np_18px_span">', '</span>'); $content=findStringBetweenAndB($getCrawling, '<article>', '</article>'); echo $regId."<br>"; echo $title."<br>"; echo $content; //등록된 아이가 있는지 확인 $subject="유머 제목1"; $sql=" select count(*) cnt from g5_write_free where wr_subject = '{$subject}' "; $list = sql_fetch($sql); if($list['cnt']===0){ echo "등록 처리"; } //0 아이디 랜덤 생성 함수 function set_uid(){ global $g5; $uid = 'u' . rand(100000, 999999); // 회원 아이디 형식 설정 $_uid = sql_fetch(" select mb_no from {$g5['member_table']} where mb_id = '{$uid}' "); if (isset($_uid['mb_no'])&&$_uid['mb_no']) set_uid(); //중복 아이디가 있으면 다시 시작함 else return $uid; } echo set_uid()."<br>"; ?>
2. 이미지 저장하기
fmkorea.php 에서 가져온 데이터 이미지만 추출후 저장하기
<?php error_reporting( E_ALL ); ini_set( "display_errors", 1 ); ini_set("allow_url_fopen", 1); header('Content-Type: text/html; charset=UTF-8'); ?> <div> <?php include_once("../common.php"); echo "추출 시작 <br>"; $getHtml = '<article><!--BeforeDocument(4855183276,4319143549)--><div class="document_4855183276_4319143549 xe_content"><p id="pi__3107430913_3483273" class="pi__3107430913_3483273">운동집안이라 평소 먹는양이 많다보니 무한리필집을 자주 찾는데(삼겹살집에서 동생이랑 둘이서 이것저것 시키면서 천천히 먹으니까 12만원 정도 나옴)</p><div>고기가 땡겨서 고기무한리필집을 검색해봤슴다.</div><div>찾던중 나오는 2년전 블로그글..행여나 중간에 망했을싶어서 전화까지해서 갔는데 다행히 영업하시더라구요ㅋㅋ</div><div><br id="pi__3107430913_3483273" class="pi__3107430913_3483273"></div><div>도착하고 드갔는데 손님은 하나도 없고 오래된 가구?나무? 냄새같은것도 나길래 좆됐다 싶었지만 이미 와버린거 먹고가자 싶어서 무한리필 B코스로 주문했습니다</div><div><br></div><div><a class="highslide highslide-move" rel="highslide" href="//image.fmkorea.com/files/attach/new2/20220725/3655304/4319143549/4855183276/7522d51fcb5a293998c0d81bef7e5d91.jpg"><img src="//image.fmkorea.com/files/attach/new2/20220725/3655304/4319143549/4855183276/7522d51fcb5a293998c0d81bef7e5d91.jpg" alt="1658751946943-5.jpg ㅗㅜㅑ미친 고깃집 발견" data-file-srl="4855183295" title=""></a><br><br></div><div>새우or오리 선택이길래 새우말씀드렸는데 새우는 9월에 나와서 목살로 대체했다는 말씀에 도망가고 싶은 마음이 굴뚝같았지만 도전.</div><div><br></div><div><a class="highslide highslide-move " rel="highslide" href="//image.fmkorea.com/files/attach/new2/20220725/3655304/4319143549/4855183276/b1ff9130e008af309dc5bee4be2e6c34.jpg"><img src="//image.fmkorea.com/files/attach/new2/20220725/3655304/4319143549/4855183276/b1ff9130e008af309dc5bee4be2e6c34.jpg" alt="1658751946943-3.jpg ㅗㅜㅑ미친 고깃집 발견" data-file-srl="4855189948" title=""></a><br><br></div><div>갑자기 사장님이 저러고 오셔서 얇게 썰어줄까 두껍게 썰어줄까 물어보시면서 퍼포먼스를 하기 시작하는데..무한리필집이 고기상태 ㅆㅅㅌㅊ</div><div><a class="highslide highslide-move" rel="highslide" href="//image.fmkorea.com/files/attach/new2/20220725/3655304/4319143549/4855183276/64406af87a2ba21ef233e10064d943d9.jpg"><img src="//image.fmkorea.com/files/attach/new2/20220725/3655304/4319143549/4855183276/64406af87a2ba21ef233e10064d943d9.jpg" alt="1658751946943-2.jpg ㅗㅜㅑ미친 고깃집 발견" data-file-srl="4855194501" title=""></a><br>불도 숯불ㄷㄷB코스에 양념갈비, 우삼겹도 있었지만 양질의 삼겹, 목살에 홀려서 달라는 생각도 못했습니다.(무한리필인데 고기가 왜이리 좋지? 하면서 한대 태우러 나가면서 보니 역시나 국내산이더라구요)</div><div><a class="highslide highslide-move" rel="highslide" href="//image.fmkorea.com/files/attach/new2/20220725/3655304/4319143549/4855183276/3002682b00bdc071c97576655629f06c.jpg"><img data-original="//image.fmkorea.com/files/attach/new2/20220725/3655304/4319143549/4855183276/3002682b00bdc071c97576655629f06c.jpg" alt="1658751946943-0.jpg ㅗㅜㅑ미친 고깃집 발견" data-file-srl="4855255163" title="" style="" class="entered exited" src="//image.fmkorea.com/classes/lazy/img/transparent.gif"></a><br><br><a class="highslide highslide-move" rel="highslide" href="//image.fmkorea.com/files/attach/new2/20220725/3655304/4319143549/4855183276/834e2978154614c67ca122d6207832c6.jpg"><img data-original="//image.fmkorea.com/files/attach/new2/20220725/3655304/4319143549/4855183276/834e2978154614c67ca122d6207832c6.jpg" alt="1658751946943-1.jpg ㅗㅜㅑ미친 고깃집 발견" data-file-srl="4855255226" title="" style="" class="entered exited" src="//image.fmkorea.com/classes/lazy/img/transparent.gif"></a><br>의도적으로 숙성을 한건지 손님이 없어서 숙성이 된건지 모르겠지만 생삼겹, 목살과는 다른 굽는떼갈에 어지간한 고기집 뺨치는 맛까지 제대로 즐기고 왔네요.</div><div><br></div><div>물론 깔끔하고 정갈한 분위기도 아니었고 무말랭이는 좀된거같아서 시큼하고 고추도 좀 되보이고 마늘도 상태가 막 좋진않았습니다ㅋㅋ</div><div>근데 고기로 장난치는 집은 아니라는걸 몸소 느꼈네요. 가격대비 역대급으로 만족한집이 아니었나 싶습니다. 너무 만족스러워서 다먹고 사장님 아이스크림까지 사다드렸네요ㅋㅋ</div><div><br></div><div>이가격에 국내산 삼겹이랑 목살을 맘껏 즐기는것도 만족스러운데 9월에 가면 새우까지 준다니 벌써 설레네요ㅋㅋ</div><div><br></div><div><br></div> <!-- serverLog: f84 --> <!-- __LAZY__CHECKED__ --></div><!--AfterDocument(4855183276,4319143549)--></article>'; // echo $getHtml; // 이미지만 추출 preg_match_all("/<img[^>]*src=[\"']?([^>\"']+)[\"']?[^>]*>/i", stripslashes($getHtml), $getImages); $valuesArray =array_values($getImages)[1]; $saveUrlImage=array(); for($i=0; $i<count($valuesArray); $i++){ //반복문으로 이미지 추출 $image=setCrawlingImg("https:".$valuesArray[$i]); array_push($saveUrlImage,$image); } function setCrawlingImg($imgUrl){ /* url 파일 가져오기 */ $img_contents=file_get_contents($imgUrl); $mDir='/fmkorea/'.date("Ymd"); $saveUrlImage=G5_DATA_URL.$mDir; $path = G5_DATA_PATH.$mDir; if (!is_dir($path)) { mkdir($path, 0777, true); } $imgName=set_img().".".end(explode(".", $imgUrl)); $saveImage=$path."/".$imgName; //디렉토리상 이미지저장 주소 $saveUrlImage=$saveUrlImage."/".$imgName; //URL 상 이미지가 보여줄 주소 /* 가져온 파일 저장하기 절대 경로 사용 , 저장할 디렉토리는 707 권한 디렉토리 */ file_put_contents($saveImage ,$img_contents); return $saveUrlImage; } //이미지명 랜덤 생성 function set_img(){ global $g5; $uid = 'img_' . rand(100000000, 999999999); return $uid; } //$getHtml 이미지 경로 변경 //echo print_r($saveUrlImage); //echo "<br><br><br>"; for($i=0; $i<count($valuesArray); $i++){ //이지지 경로명 변경 $getHtml=str_replace($valuesArray[$i], $saveUrlImage[$i], $getHtml); } time_sleep_until(time() + 2); //2초간 지연 echo print_r($getHtml); exit(); if(unlink($saveImage)){ // echo $saveImage." - 파일 삭제 성공"; } ?> <h1><a href="?mode=daumNews">다음 메인 뉴스</a></h1> <h1> <a href="?mode=nexchange">네이버 환율정보</a></h1><br> </div> <div> <?php $mode=$_GET['mode']; switch ($mode) { case "daumNews": // 네이버 급상승 검색어 echo "<h1>다음 뉴스</h1>"; $curl = curl_init('https://www.daum.net/'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); $page = curl_exec($curl); if (curl_errno($curl)){ echo 'Scraper error: ' . curl_error($curl); exit(); } curl_close($curl); $regex = '/<h3 class="screen_out">(.*?)<\/h3>/s'; if (preg_match($regex, $page, $list)) echo $list[0]; break; // 네이버 환율정보 case "nexchange": echo "<h1>네이버 환율정보</h1>"; $curl = curl_init('https://finance.naver.com/marketindex/exchangeList.nhn'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); // TRUE로 설정 시 curl_exec()의 반환 값을 문자열로 반환 $page = curl_exec($curl); if (curl_errno($curl)){ echo 'Scraper error: ' . curl_error($curl); exit(); } curl_close($curl); $regex = '/<div class="tbl_area">(.*?)<\/div>/s'; if (preg_match($regex, $page, $list)) $extract=iconv("EUC-KR", "UTF-8", $list[0]); echo str_replace('<a href="/marketindex/' , '<a target="_blank" href="https://finance.naver.com/marketindex/' ,$extract); break; // 네이버 환율정보 default: echo ""; break; } ?> </div>
2022-07-26 22:49:13
macaronics.net 는 그어떠한 동영상, 이미지, 파일등을 직접적으로 업로드 제공을 하지 않습니다. 페이스북, 트위터 등 각종 SNS 처럼 macaronics.net 는 웹서핑을 통하여 각종 페이지위치등을 하이퍼링크, 다이렉트링크, 직접링크등으로 링크된 페이지 주소만을 수집 저장하여 제공하고 있습니다. 저장된 각각의 주소에 연결된 페이지등은 그 페이지에서 제공하는 "서버, 사이트" 상황에 따라 페이지와 내용이 삭제 중단 될 수 있으며 macaronics.net 과는 어떠한 연관 관련이 없음을 알려드립니다. 또한, 저작권에 관련된 문제있는 글이나 기타 저작권에 관련된 문제가 있는 것은 연락주시면 바로 삭제해 드리겠습니다.
댓글 ( 4)
댓글 남기기