コードをコピー コードは次のとおりです:
//HTML を収集
function getwebcontent($url){
$ ch =curl_init ();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT) , $timeout );
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
$contents = trim(curl_exec($ch)); 🎜>}
//タイトルと URL を取得
$string =
getwebcontent('http://www.***.com/learn/zhunbeihuaiyun/jijibeiyun/2' );
//通常の一致
タイトルとアドレスを取得
preg_match_all ("/(.*)< ;/ a>/",$string, $out, PREG_SET_ORDER);
foreach($out as $key => $value){
$article['title'][] = $out[$key ] [2];
$article['link'][] = "http://www.***.com/learn/article/".$out[$key][1]; }
//URL に基づいて記事のコンテンツを取得します
foreach($article['link'] as $key=>$value){
$content_html = getwebcontent($article['link' ][$key ]);
preg_match("/
[s|S]*?
/",$content_html,$matches); >$article[ content][$key] = $matches[0];
}
//実際にはトランスコードしないとファイルとして保存できません
foreach($article[title ] as $key=> $value){
$article[title][$key] = iconv('utf-8', 'gbk', $value);//トランスコーディング
}
//ファイルに保存
$num = count($article['title']);
for($i=0; $ifile_put_contents("{$記事[タイトル][$ i]}.txt", $article['content'][$i]);
}
?>