抓取豆瓣电影TOP250的PHP代码
2018-07-20 来源:open-open
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);
}
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
最新资讯
热门推荐