신문 기사를 긁어오기^^

· 19년 전 · 3059 · 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,823
19년 전 조회 2,431
19년 전 조회 2,440
19년 전 조회 2,934
19년 전 조회 5,867
19년 전 조회 5,654
19년 전 조회 2,333
19년 전 조회 3,395
19년 전 조회 2,960
19년 전 조회 2,308
19년 전 조회 2,819
19년 전 조회 1,676
19년 전 조회 1,839
19년 전 조회 1,928
19년 전 조회 2,103
19년 전 조회 1,771
19년 전 조회 1,912
19년 전 조회 1,868
19년 전 조회 1,952
19년 전 조회 1,625
19년 전 조회 2,744
19년 전 조회 2,067
19년 전 조회 3,324
19년 전 조회 3,364
19년 전 조회 2,628
19년 전 조회 2,697
19년 전 조회 2,530
19년 전 조회 2,781
19년 전 조회 2,780
19년 전 조회 3,254
19년 전 조회 2,971
19년 전 조회 5,373
19년 전 조회 2,206
19년 전 조회 2,282
19년 전 조회 2,112
19년 전 조회 2,020
19년 전 조회 2,022
19년 전 조회 2,218
19년 전 조회 3,291
19년 전 조회 3,152
19년 전 조회 2,935
19년 전 조회 2,641
19년 전 조회 2,730
19년 전 조회 2,383
19년 전 조회 2,419
19년 전 조회 1,691
19년 전 조회 2,406
19년 전 조회 2,763
19년 전 조회 2,767
19년 전 조회 3,060
19년 전 조회 2,840
19년 전 조회 1,807
19년 전 조회 1,915
19년 전 조회 2,823
19년 전 조회 2,310
19년 전 조회 4,065
19년 전 조회 2,571
19년 전 조회 2,467
19년 전 조회 3,609
19년 전 조회 3,196
19년 전 조회 2,322
19년 전 조회 3,121
19년 전 조회 2,319
19년 전 조회 3,167
19년 전 조회 3,578
19년 전 조회 5,288
19년 전 조회 3,201
19년 전 조회 3,224
19년 전 조회 2,807
19년 전 조회 2,538
19년 전 조회 2,784
19년 전 조회 2,528
19년 전 조회 2,637
19년 전 조회 2,437
19년 전 조회 2,784
19년 전 조회 3,053
19년 전 조회 3,328
19년 전 조회 7,139
19년 전 조회 5,263
19년 전 조회 2,503
19년 전 조회 5,244
19년 전 조회 3,192
19년 전 조회 2,537
19년 전 조회 2,221
19년 전 조회 3,660
19년 전 조회 2,973
19년 전 조회 3,353
19년 전 조회 2,976
19년 전 조회 3,476
19년 전 조회 2,792
19년 전 조회 3,533
19년 전 조회 2,497
19년 전 조회 4,190
19년 전 조회 3,376
19년 전 조회 4,204
19년 전 조회 3,564
19년 전 조회 3,208
19년 전 조회 3,483
19년 전 조회 2,535
19년 전 조회 2,921