>  기사  >  php教程  >  php抓取百度贴吧图片

php抓取百度贴吧图片

PHP中文网
PHP中文网원래의
2016-05-25 17:07:05897검색

php代码

<?php
//运行时间
@set_time_limit(60);
//贴吧名称
$tbname = "%CD%BC%C6%AC";
//抓取类型 0-按照帖子顺序 1-按照贴图顺序
$type = 0;
//列表页url
$listurltpl = "http://tieba.baidu.com/f?kw=%s".($type?"&tp=1":"&pn=");
//图册页url
$galleryurltpl = "http://tieba.baidu.com/photo/bw/picture/guide?kw=%s&tid=%s&next=9999";
//图片url
$imageurltpl = "http://imgsrc.baidu.com/forum/pic/item/%s.jpg";
//本地的目录
$savepath = "h:/images/";
//帖子子文件夹
$filedirtpl = $savepath."%s/";
//图片文件
$filenametpl = $savepath."%s/%s.jpg";

$listurl = sprintf($listurltpl,$tbname);
//抓取起始点
$pn = 0;
while(1)
{
	if (!$type) $listurl .= $pn;
	//得到列表页源代码
	$listhtml = file_get_contents($listurl);
	//匹配出帖子id
	if($type)
		preg_match_all(&#39;/

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.