Aiting's Blog-艾丁堡

生活*爱情*随想*感知

;test.php 从baidu的搜索页面提取需要的信息集中存入数据库

;-----------------------------------

<?php
include ("config.php");

for($j=1;$j<=8;$j++)
{
$pn=($j-1)*100;
$url = "http://www.baidu.com/s?lm=0&si=&rn=100&ie=gb2312&ct=0&wd=%C5%A9%D2%B5%D0%C5%CF%A2&pn=".$pn."&cl=3";
$filefrom = implode ('', file($url));
$filefrom = strstr($filefrom,'<ol>');
$filefrom2 = strstr($filefrom,'</ol>');
$filefrom3 = explode($filefrom2,$filefrom);
$filefrom = $filefrom3[0];
//以上是截取<ol></ol>之间信息的代码,有点乱

$xx1 = '<p class=p1>';
$xx2 = '<br>';
$xx = explode($xx1,$filefrom);
for($i=1;$i<=100;$i++)
{
 $ii=$i+($j-1)*100;
 $every_item = explode($xx2,$xx[$i]);
 $url = explode('/',$every_item[4]);
 $url = substr($url[0],20);
 echo '<p>'.$ii.')'.'<p>';
 echo $every_item[0].'<br>';
 echo $every_item[4].'<br>';
 echo $every_item[5].'<br>';
 echo 'http://'.$url;
 echo '<p>';
 
 
 $url = 'http://'.$url;
 $title = $every_item[0];
 $content = "";
 $keywords = "农业信息";
 $hits = 1;
 $buff = substr($url,11);
 $buff1 = substr($url,7);
 if($buff != "http://www.")
 {
  $first_chat = substr($buff,0,1);
  
 }
 else
 {
  $first_chat = substr($buff1,0,1);
 }
 echo "首字母".$first_chat;
 /*
 $result=mysql_query("
 INSERT INTO `test_test1` ( `id` , `url` , `title` , `content` , `rank` , `time` , `first_chat` , `hits` )
VALUES (
'', '$url', '$title', '$content', '农业信息', Now(), '$first_chat', '1'
);");
 echo "写入了一条新信息";*/
}
}?>

;test2.php 生成execl表格

<?php 
//  转载请注明phpteam 
$title  =  "数据库名:test,  数据表:test_test1,  备份日期:"  .  date("Y-m-d  H:i:s"); 
$sep  =  "\t"; 
$crlf  =  "\n"; 
 
$conn  =  @mysql_connect("xxx","xxx","xxx")  or  die("不能连接数据库"); 
@mysql_select_db("test",  $conn); 
header("Content-Type:  application/vnd.ms-excel"); 
header("Content-Disposition:  attachment;  filename=test.xls"); 
header("Pragma:  no-cache"); 
header("Expires:  0"); 
 
echo  $title  .  $crlf  .  $crlf; 
 
$query  =  "select  *  from  test_test1"; 
$result  =  mysql_query($query)  or  die(mysql_error()); 
$fields  =  mysql_num_fields($result); 
for($i  =  0;  $i  <  $fields;  $i++)  { 
       echo  mysql_field_name($result,  $i)  .  $sep; 

echo  $crlf; 
while($row  =  mysql_fetch_row($result))  { 
       $line  =  ""; 
       for($i  =  0;  $i<$fields;  $i++)  { 
               $line  .=  $row[$i]  .  $sep; 
       } 
       echo  $line  .  $crlf; 

?> 



Trackback: http://tb.donews.net/TrackBack.aspx?PostId=395121


[点击此处收藏本文]  发表于2005年05月24日 7:33 AM




正在读取评论……

发表评论

大名:
网址:
验证码
评论 
   

news

把生活淡化,

淡到心领神会,

淡到百折不挠。

访问:

导航

blog stats

文章

收藏

相册

CAU

JAVA

网页设计

新闻

信息

友情链接

存档


正在读取评论……