PHP - 抓取电视剧资源

<?php
/**
 * 获取下载url
 * @return [type] [description]
 */
function getVedioDwonloadUrl() {
	for ($i=1; $i <= 48; $i++) {
		$url = 'http://www.btdog.com/play/34821-1-' . $i . '.html';
		$urlContent[] = patternHtml( getUrlContent( $url ) );
	}
	return $urlContent;
}

/**
 * 匹配内容
 * @param  [type] $content [description]
 * @return [type]          [description]
 */
function patternHtml( $content ) {
	//Analytical content.
	$pattern = '/<div.*?class="pdcc.*?liji"><a.*?href="([\s\S]*?)"><img.*?src="([\s\S]*?)"><\/a><\/div>/';
	preg_match_all( $pattern, $content, $contentArray);
	return $contentArray[1][0];
}

/**
 * 获取html内容
 * @param  [type] $url [description]
 * @return [type]      [description]
 */
function getUrlContent( $url ) {
	return file_get_contents( $url );
}

/**
 * 写入文件
 * @param  [type] $str [description]
 * @return [type]      [description]
 */
function writeFile( $arr ) {
	foreach ($arr as $v) {
		file_put_contents( 'C:\\Users\\Administrator\\Desktop\\1.txt', $v . EOF, FILE_APPEND );	
	}
}


$start_time=microtime(true);
$temp = getVedioDwonloadUrl();
$end_time=microtime(true);
$total=round( $end_time-$start_time, 2 );
echo "总耗时:$total<br/>";
print_r( $temp );

  

posted on 2016-04-15 17:57  ultrastrong  阅读(421)  评论(0编辑  收藏  举报