前面介绍的爬虫程序,通过预先设置的规则将数据从目标站点下载到数据库中。现在需要写一个脚本程序将数据库中的内容以列表的形式展示出来,同时还要提供"修改"链接用来编辑、调整内容。采集内容列表程序的代码如下:
广州网站建设
- <?php
- $con = mysql_connect ( 'localhost', 'root', 'password' ) or die ( 'Could not connect: ' . mysql_error () );
- mysql_query ( "set names gb2312" ); //设定数据字符集
- echo 'Connected successfully';
- $db = mysql_select_db ( 'get_content', $con ); //实例化数据库连接
- if (! $db) {
- die ( "Can\'t use download : " . mysql_error () ); //数据库异常报错抛出
- } else {
- //获得文件详细信息
- $sql = "SELECT * FROM 'articles' LIMIT 0,10 ";
- $result = mysql_query ( $sql, $con );
- $num_rows = mysql_num_rows ( $result );
- //$rows=mysql_fetch_array($result);
- //var_dump ($rows);
- }
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gbk" />
- </head>
- <link href="admin.css" rel="stylesheet" type="text/css" />
- <base target="mainFrame">
- <div class="m"></div>
- <div class="t">
- <table align=center cellspacing=0 cellpadding=0>
- <tr class=head>
- <td colspan="4">栏目名称</td>
- </tr>
- <tr class=line>
- <td><strong>日期</strong></td>
- <td width="913"><strong>标题</strong></td>
- <td><strong>修改</strong></td>
- </tr>
- <?php
- for($i = 0; $i < $num_rows; $i ++) {
- ?>
- <tr class=line>
- <td width="135">
- <?php
- $row = mysql_fetch_array ( $result );
- echo $row ['Date'];
- ?>
- </td>
- <td>
- <?php
- echo $row ['Title'];
- ?>
- </td>
- <td width="83"><a
- href="articles_save.php?aid=<? phpecho $row ['ID'];?>" target="_top"> 修改</a></td>
- </tr>
- <?php
- }
- ?>
- <tr class=line>
- <td colspan="4" align="center"> </td>
- </tr>
- </table>
- </div>
![]() |
| (点击查看大图)图8.4 文章列表 |




