抓取的网页如何存入mysql数据库
写的一个PHP代码(test.php):
$url = "http://www.baidu.com/";?
$contents = file_get_contents($url);?
echo $contents;?>?
如何把抓取的这个网页数据mysql数据库中呢? 表是Page 字段1:Pageid | 字段2:Pagetext
求代码
------解决方案--------------------
不就是一句 insert into 了?
值都有了,字段也有了。。。
------解决方案--------------------
若果pageid是自增的。则空缺也可。
$sql="insert into `Page` values ('','$contents')";
------解决方案--------------------
preg_match_all('/
$contents = file_get_contents('a.php');
preg_match_all('/(<h1.>)/iUs', $contents, $match);
//如果有多个需要匹配的结果 自己输出 match数组 组织成字符串...
$contents = $match[1][0];
mysql_connect('localhost', 'root', '');
mysql_select_db("lookdb");
mysql_query("SET NAMES 'GBK'");
$SQL = "INSERT INTO page (pagetext) VALUES('{$contents}')";
mysql_query($SQL); <div class="clear"></div></h1.>
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号