抓取豆瓣电影TOP250的PHP代码

2015-11-14 0 597
抓取豆瓣电影TOP250的PHP代码
for ($start = 0; $start < 250; $start += 25) {
    $url = "http://movie.douban.com/top250?start=$start&filter=&type=";
    $titles = parsePage($url);
    if ($titles === false) {
        echo $url, "\n";
    } else {
        array_walk($titles, 'printTitle');
    }
}
 
 
function parsePage($url) {
    $html = file_get_contents($url);
    if ($html === false) {
        return false;
    }
     
    if (preg_match_all('/<a.+?<span class="title">([^<]+)/s', $html, $matches) === false) {
        return false;
    }
     
    $titles = array();
    foreach($matches[1] as $item) {
        $titles[] = iconv('utf-8', 'gbk', $item);
    }
    return $titles;
}
 
 
$count = 0;
function printTitle($title) {
    global $count;
    ++$count;
    printf("%3d %s\n", $count, $title);
}

遇见资源网 php 抓取豆瓣电影TOP250的PHP代码 http://www.ox520.com/8060.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务