批量获取某电影网站的下载链接

2017-05-20 02:14:33 +08:00
 liuwenxu
php 爬取网站下华语分类下的所有链接,匹配出 ftp 开头的下载链接,大概 1000 左右页面。直接放数组去重,貌似抓取到 300 页,程序就死掉了。有没有好的意见?
2538 次点击
所在节点    问与答
7 条回复
Wetoria
2017-05-20 03:26:49 +08:00
死掉是什么缘故?感觉你说的是内存崩了?

如果不是反爬虫,数据用数据库存呗,链接做主键,去重就简单了。

反爬虫的话,要针对性的应对了咯
Srar
2017-05-20 04:04:26 +08:00
yangqi
2017-05-20 04:08:20 +08:00
代码写太烂了
liuwenxu
2017-05-20 05:07:20 +08:00
贴下代码 大家可以跑下,就现有的逻辑可以优化吗?目前我只能手动每次 20,但是以后网站更新就太麻烦
$begin="http://www.ygdy8.net/html/gndy/china/list_4_2.html";
$data=array();
$detail=array();
for ($i=70; $i <90; $i++) {
$url="http://www.ygdy8.net/html/gndy/china/list_4_{$i}.html";
$str=file_get_contents($url);
if($str){
preg_match_all("/href=\"(.*?)\"/", $str,$urll);
foreach ($urll[1] as $key => $value) {
if (strpos($value, "gndy/dyzz/")) {
if(!in_array($value, $detail)){
$detail[]=$value;
}

}

}
}
}
print_r($detail);
$base="http://www.ygdy8.net";
foreach ($detail as $key => $value) {
$strs=file_get_contents($base.$value);
if($strs&&preg_match("/(ftp.*?)\"/", $strs,$urlls)){
if(!in_array($urlls[1], $data)){
$data[]=$urlls[1];

}

}
}
print_r($data);
$has=file("data.txt");
foreach ($data as $key => $value) {
if(empty($has)||!in_array($value, $has)){
$value=iconv("gbk", "utf-8", $value);
file_put_contents("data.txt", $value.PHP_EOL,FILE_APPEND);
}
}
UnisandK
2017-05-20 08:03:02 +08:00
file_get_contents 卡上了吧
jugelizi
2017-05-20 08:37:00 +08:00
php 最大运行时间 30s
sarices
2017-05-20 09:14:13 +08:00
走队列

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/362567

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX