신문 기사를 긁어오기^^

· 19년 전 · 2961 · 3
<?

function get($url){//문서가져옮
$fp = fopen($url, "r");

while(!feof($fp)){
$tmp = fgets($fp, 900);
$temp .= $tmp;
}

fclose($fp);

return $temp;
}//function get

function Strip($all){// 링크랑 제목만 빼오기

$link_pm=strpos($all,">");

$link=substr($all,0,$link_pm);

if(!$link) return;

if(ereg("\"",$link)){

$link_p=strpos($link,"\"");
$link=substr($link,$link_p+1);
$link_p=strpos($link,"\"");

$link=substr($link,0,$link_p);
}

if(ereg("'",$link)){

$link_p=strpos($link,"'");
$link=substr($link,$link_p+1);
$link_p=strpos($link,"'");

$link=substr($link,0,$link_p);
}

$link=trim($link);

$substr=substr($all,$link_pm+1);
$substr_p=strpos($substr,"</a>");
$substr=substr($substr,0,$substr_p);
$strip=strip_tags($substr);
$strip=trim($strip);

return array(link => $link, sub => $strip);
}//function strip($all)

function makeUrl($Url, $Link){

if(!strpos($Link,"http://") && substr_count("$Link","http://")) return $Link;

$eURL = pathinfo("$Url");

$host = parse_url($Url);
$host = $host[scheme]."://".$host[host];

$Link = "/".$Link; //링크가 루트인지 확인위해 임의로 붙인다.
if(substr_count("$Link","../")){ //한칸앞으로

$Link = str_replace("./../", "", $Link);
$Link = str_replace("../", "", $Link);

$pos = strrpos($eURL["dirname"], "/");
$makeUrl = substr($eURL["dirname"],0,$pos);

$makeUrl = "$makeUrl"."$Link";

}else if(substr_count("$Link","//") && !strpos($Link, "//")){ //루트로 가라

$makeUrl = $host."/".str_replace("//", "", $Link);

}else{ //제자리

$Link = str_replace("./", "", $Link);
$makeUrl = $eURL["dirname"]."$Link";
}

return $makeUrl;
}
////////////////////////////////////// 펑션끝
$date_Y = date("Y");
$date_M = date("m");
$date_D = date("d");

$mdate = "$date_Y.$date_M.$date_D"; //확장성 위해
////////////////////////////////////////////////////////////<== 신문사별설정 추가가능

$newspaper[] = "동아일보";
$URL[] = "http://www.donga.com/fbin/output?f=total";
$like[] = "$date_Y$date_M$date_D";

$newspaper[] = "연합신문";
$URL[] = "http://www.yonhapnews.co.kr/services/0400000000.html";
$like[] = "$date_Y$date_M$date_D";

////////////////////////////////////////////////////////////<== 여기까지 신문사별설정

for($x=0; $x < sizeof($newspaper); $x++){

$temp = get($URL[$x]);

$all = split("href =|HREF =|href=|HREF=",$temp);//--> url 추출

for($i=0; $i < sizeof($all); $i++){

$kisa = Strip($all[$i]);

if(ereg($like[$x], $kisa[link]) & 20 < strlen($kisa[sub])){

$LinkURL = makeUrl($URL[$x], $kisa[link]);
echo "<a href='$LinkURL'>[$newspaper[$x]]$kisa[sub]</a><br>";
}//if(ereg($like[$x], $kisa[link]) & 20 < strlen($kisa[sub]))
}//for($i=0; $i < sizeof($all); $i++)
}//for($x=0; $x < sizeof($newspaper); $x++)
?><div class='small'>[이 게시물은 관리자님에 의해 2011-10-31 17:12:10 PHP & HTML에서 이동 됨]</div>
|

댓글 3개

기타 신문기사의 주소는 스스로 찾으면 되더군요..
아래는 예를 들었습니다.
////////////////////////////////////////////////////////////<== 신문사별설정 추가가능



$newspaper[] = "<font color=cc0000>굿</font>";
$URL[] = "http://www.hot.co.kr/sports/list.html";
$like[] = "$date_Y$date_M$date_D";



////////////////////////////////////////////////////////////<== 여기까지 신문사별설정
긁어올수 있는 신문기사 주소는 어떻게 찾나요?
특별한 방법이 있는지요?
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

+
제목 글쓴이 날짜 조회
19년 전 조회 3,728
19년 전 조회 2,331
19년 전 조회 2,356
19년 전 조회 2,845
19년 전 조회 5,773
19년 전 조회 5,556
19년 전 조회 2,249
19년 전 조회 3,289
19년 전 조회 2,855
19년 전 조회 2,206
19년 전 조회 2,725
19년 전 조회 1,578
19년 전 조회 1,733
19년 전 조회 1,829
19년 전 조회 2,003
19년 전 조회 1,683
19년 전 조회 1,813
19년 전 조회 1,774
19년 전 조회 1,851
19년 전 조회 1,526
19년 전 조회 2,646
19년 전 조회 1,984
19년 전 조회 3,236
19년 전 조회 3,268
19년 전 조회 2,522
19년 전 조회 2,607
19년 전 조회 2,431
19년 전 조회 2,689
19년 전 조회 2,680
19년 전 조회 3,160
19년 전 조회 2,872
19년 전 조회 5,279
19년 전 조회 2,107
19년 전 조회 2,187
19년 전 조회 2,005
19년 전 조회 1,928
19년 전 조회 1,928
19년 전 조회 2,121
19년 전 조회 3,197
19년 전 조회 3,067
19년 전 조회 2,842
19년 전 조회 2,540
19년 전 조회 2,619
19년 전 조회 2,284
19년 전 조회 2,327
19년 전 조회 1,594
19년 전 조회 2,315
19년 전 조회 2,662
19년 전 조회 2,656
19년 전 조회 2,962
19년 전 조회 2,738
19년 전 조회 1,709
19년 전 조회 1,815
19년 전 조회 2,715
19년 전 조회 2,216
19년 전 조회 3,974
19년 전 조회 2,482
19년 전 조회 2,369
19년 전 조회 3,513
19년 전 조회 3,090
19년 전 조회 2,227
19년 전 조회 3,022
19년 전 조회 2,232
19년 전 조회 3,081
19년 전 조회 3,500
19년 전 조회 5,194
19년 전 조회 3,113
19년 전 조회 3,122
19년 전 조회 2,710
19년 전 조회 2,444
19년 전 조회 2,699
19년 전 조회 2,435
19년 전 조회 2,550
19년 전 조회 2,345
19년 전 조회 2,689
19년 전 조회 2,955
19년 전 조회 3,247
19년 전 조회 7,048
19년 전 조회 5,164
19년 전 조회 2,423
19년 전 조회 5,146
19년 전 조회 3,100
19년 전 조회 2,447
19년 전 조회 2,139
19년 전 조회 3,570
19년 전 조회 2,881
19년 전 조회 3,253
19년 전 조회 2,879
19년 전 조회 3,373
19년 전 조회 2,699
19년 전 조회 3,446
19년 전 조회 2,406
19년 전 조회 4,094
19년 전 조회 3,281
19년 전 조회 4,126
19년 전 조회 3,468
19년 전 조회 3,096
19년 전 조회 3,392
19년 전 조회 2,436
19년 전 조회 2,841