• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

如何取出百度某排行榜50条并在每条加前后缀呢

php 搞代码 3年前 (2022-01-24) 12次浏览 已收录 0个评论

怎么取出百度某排行榜50条并在每条加前后缀呢
如http://top.baidu.com/buzz?b=26&c=1&fr=topcategory_c1

——解决思路———————-
帶輸出的完整例子,你好好學習下。
中間你想改什麼,直接改就可以了。

<br /><?php<br />function getContent($url){<br />	$ch = curl_init();<br />	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);	<br />	curl_setopt($ch, CURLOPT_URL, $url);<br />	curl_setopt($ch, CURLOPT_TIMEOUT, 300);<br />	$response = curl_exec($ch);<br />	if($error=curl_error($ch)){<br />		die($error);<br />	}<br />	curl_close($ch);<br /><br />	$content = iconv('GBK','UTF-8//IGNORE',$response);<br /><br />	return $content;<br />}<br /><br />function getKeywords($content){<br />	// keywords<br />	preg_match_all('/<td class="keyword">(.*?)<\/td>/is', $content, $keywords);<br />	$data = $keywords[1];<br /><br />	$result = array();<br /><br />	foreach($data as $val){<br />		preg_match_all('/(.*?)<\/a>/is', $val, $tmp);<br />		array_push($result, array('name'=>$tmp[2][0],'url'=>'http://top.baidu.com'.substr($tmp[1][0],1)));<br />	}<br /><br />	return $result;<br />}<br /><br />function getTc($content){<br />	// tc<br />	preg_match_all('/<td class="tc">(.*?)<\/td>/is', $content, $tc);<br /><br />	$data = $tc[1];<br /><br />	$result = array();<br /><br />	foreach($data as $val){<br />		preg_match_all('/(.*?)<\/a>/is', $val, $tmp);<br />		array_push($result, array('brief'=>$tmp[1][0], 'news'=>$tmp[1][1], 'tieba'=>$tmp[1][2]));<br />	}<br /><br />	return $result;<br />}<br /><br />function getNum($content){<br />	// last<br />	preg_match_all('/<td class="last">(.*?)<\/td>/is', $content, $last); //icon-rise up icon-fall down<br /><br />	$data = $last[1];<br /><br />	$result = array();<br /><br />	foreach($data as $val){<br />		preg_match_all('/<span>(.*?)<\/span>/is', $val, $tmp);<br />		array_push($result, array('flag'=>str_repla<p style="color:transparent">本文来源gao!%daima.com搞$代*!码$网3</p><strong>搞代gaodaima码</strong>ce('icon-','',$tmp[1][0]), 'num'=>$tmp[2][0]));<br />	}<br /><br />	return $result;<br />}<br /><br />$url = 'http://top.baidu.com/buzz?b=340&c=1&fr=topbuzz_b339_c1';<br />$content = getContent($url);<br />$result = array();<br /><br />$keywords = getKeywords($content);<br />$tc = getTc($content);<br />$num = getNum($content);<br /><br />for($i=0,$len=count($keywords); $i<$len; $i++){<br />	$tmp = array(<br />		'name' => $keywords[$i]['name'],<br />		'url' => $keywords[$i]['url'],<br />		'brief' => $tc[$i]['brief'],<br />		'news' => $tc[$i]['news'],<br />		'tieba' => $tc[$i]['tieba'],<br />		'flag' => $num[$i]['flag'],<br />		'num' => $num[$i]['num']<br />	);<br />	array_push($result, $tmp);<br />}<br />?><br /><br /><br /> <br />  <meta http-equiv="content-type" content="text/html;charset=utf-8"><br />  <title> baidu </title><br /> <br /><br /> <body><br />	<table><br />	<?php<br />	$i = 1;<br />	foreach($result as $val){<br />	?><br />	<tr><br />		<td><?=$i ?></td><br />		<td>"><?=$val['name'] ?></td><br />		<td>">簡介</td><br />		<td>">新聞</td><br />		<td>">貼吧</td><br />		<td><?php if($val['flag']=='fall'){ echo '↓'; }else{echo '↑'; } ?><?=$val['num'] ?></td><br />	</tr><br />	<?php<br />		$i++;<br />	}<br />	?><br />	</table><br /> <br /><br />

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:如何取出百度某排行榜50条并在每条加前后缀呢
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址