如何编写PHP脚本抓取豆瓣电影TOP250排名列表?

更新于
2026-09-26 06:48:44
1阅读来源:SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计122个文字,预计阅读时间需要1分钟。

如何编写PHP脚本抓取豆瓣电影TOP250排名列表?

phpfor ($start=0; $start <250; $start +=25) { $url=http://movie.douban.com/top250?start=$start&filter=color; $titles=parsePage($url); if ($titles===false) { echo $url, \n; } else { array_walk($titles, 'printTitle'); }}

如何编写PHP脚本抓取豆瓣电影TOP250排名列表?

for ($start = 0; $start < 250; $start += 25) { $url = "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代码forS

本文共计122个文字,预计阅读时间需要1分钟。

如何编写PHP脚本抓取豆瓣电影TOP250排名列表?

phpfor ($start=0; $start <250; $start +=25) { $url=http://movie.douban.com/top250?start=$start&filter=color; $titles=parsePage($url); if ($titles===false) { echo $url, \n; } else { array_walk($titles, 'printTitle'); }}

如何编写PHP脚本抓取豆瓣电影TOP250排名列表?

for ($start = 0; $start < 250; $start += 25) { $url = "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代码forS