신문 기사를 긁어오기^^

· 19년 전 · 3012 · 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,772
19년 전 조회 2,378
19년 전 조회 2,399
19년 전 조회 2,889
19년 전 조회 5,820
19년 전 조회 5,602
19년 전 조회 2,287
19년 전 조회 3,335
19년 전 조회 2,898
19년 전 조회 2,255
19년 전 조회 2,772
19년 전 조회 1,625
19년 전 조회 1,782
19년 전 조회 1,877
19년 전 조회 2,050
19년 전 조회 1,725
19년 전 조회 1,867
19년 전 조회 1,822
19년 전 조회 1,895
19년 전 조회 1,576
19년 전 조회 2,695
19년 전 조회 2,027
19년 전 조회 3,285
19년 전 조회 3,313
19년 전 조회 2,573
19년 전 조회 2,651
19년 전 조회 2,484
19년 전 조회 2,732
19년 전 조회 2,731
19년 전 조회 3,206
19년 전 조회 2,914
19년 전 조회 5,328
19년 전 조회 2,153
19년 전 조회 2,241
19년 전 조회 2,062
19년 전 조회 1,972
19년 전 조회 1,976
19년 전 조회 2,171
19년 전 조회 3,243
19년 전 조회 3,109
19년 전 조회 2,888
19년 전 조회 2,592
19년 전 조회 2,672
19년 전 조회 2,336
19년 전 조회 2,372
19년 전 조회 1,642
19년 전 조회 2,359
19년 전 조회 2,712
19년 전 조회 2,704
19년 전 조회 3,013
19년 전 조회 2,789
19년 전 조회 1,752
19년 전 조회 1,860
19년 전 조회 2,773
19년 전 조회 2,259
19년 전 조회 4,019
19년 전 조회 2,524
19년 전 조회 2,414
19년 전 조회 3,561
19년 전 조회 3,129
19년 전 조회 2,274
19년 전 조회 3,063
19년 전 조회 2,277
19년 전 조회 3,125
19년 전 조회 3,531
19년 전 조회 5,243
19년 전 조회 3,154
19년 전 조회 3,162
19년 전 조회 2,751
19년 전 조회 2,489
19년 전 조회 2,739
19년 전 조회 2,479
19년 전 조회 2,592
19년 전 조회 2,398
19년 전 조회 2,729
19년 전 조회 3,003
19년 전 조회 3,281
19년 전 조회 7,083
19년 전 조회 5,210
19년 전 조회 2,464
19년 전 조회 5,196
19년 전 조회 3,144
19년 전 조회 2,488
19년 전 조회 2,170
19년 전 조회 3,609
19년 전 조회 2,926
19년 전 조회 3,299
19년 전 조회 2,919
19년 전 조회 3,421
19년 전 조회 2,740
19년 전 조회 3,487
19년 전 조회 2,448
19년 전 조회 4,144
19년 전 조회 3,327
19년 전 조회 4,165
19년 전 조회 3,509
19년 전 조회 3,156
19년 전 조회 3,433
19년 전 조회 2,478
19년 전 조회 2,880