신문 기사를 긁어오기^^

· 19년 전 · 2955 · 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,721
19년 전 조회 2,327
19년 전 조회 2,350
19년 전 조회 2,838
19년 전 조회 5,770
19년 전 조회 5,550
19년 전 조회 2,243
19년 전 조회 3,285
19년 전 조회 2,849
19년 전 조회 2,203
19년 전 조회 2,719
19년 전 조회 1,574
19년 전 조회 1,729
19년 전 조회 1,822
19년 전 조회 1,997
19년 전 조회 1,677
19년 전 조회 1,804
19년 전 조회 1,770
19년 전 조회 1,843
19년 전 조회 1,521
19년 전 조회 2,640
19년 전 조회 1,977
19년 전 조회 3,228
19년 전 조회 3,261
19년 전 조회 2,515
19년 전 조회 2,603
19년 전 조회 2,428
19년 전 조회 2,687
19년 전 조회 2,670
19년 전 조회 3,153
19년 전 조회 2,866
19년 전 조회 5,275
19년 전 조회 2,103
19년 전 조회 2,183
19년 전 조회 1,998
19년 전 조회 1,922
19년 전 조회 1,923
19년 전 조회 2,116
19년 전 조회 3,191
19년 전 조회 3,062
19년 전 조회 2,837
19년 전 조회 2,536
19년 전 조회 2,614
19년 전 조회 2,277
19년 전 조회 2,324
19년 전 조회 1,586
19년 전 조회 2,308
19년 전 조회 2,653
19년 전 조회 2,648
19년 전 조회 2,956
19년 전 조회 2,732
19년 전 조회 1,703
19년 전 조회 1,810
19년 전 조회 2,708
19년 전 조회 2,209
19년 전 조회 3,968
19년 전 조회 2,476
19년 전 조회 2,363
19년 전 조회 3,507
19년 전 조회 3,085
19년 전 조회 2,223
19년 전 조회 3,017
19년 전 조회 2,227
19년 전 조회 3,077
19년 전 조회 3,492
19년 전 조회 5,189
19년 전 조회 3,110
19년 전 조회 3,116
19년 전 조회 2,702
19년 전 조회 2,439
19년 전 조회 2,694
19년 전 조회 2,430
19년 전 조회 2,544
19년 전 조회 2,340
19년 전 조회 2,684
19년 전 조회 2,950
19년 전 조회 3,242
19년 전 조회 7,041
19년 전 조회 5,159
19년 전 조회 2,418
19년 전 조회 5,142
19년 전 조회 3,092
19년 전 조회 2,442
19년 전 조회 2,133
19년 전 조회 3,565
19년 전 조회 2,876
19년 전 조회 3,246
19년 전 조회 2,875
19년 전 조회 3,371
19년 전 조회 2,692
19년 전 조회 3,440
19년 전 조회 2,397
19년 전 조회 4,086
19년 전 조회 3,274
19년 전 조회 4,116
19년 전 조회 3,465
19년 전 조회 3,092
19년 전 조회 3,388
19년 전 조회 2,431
19년 전 조회 2,837