php如何抓取网页数据(抓取的网页如何存入mysql数据库写的一个PHP代码(test.php))
优采云 发布时间: 2021-09-12 12:00php如何抓取网页数据(抓取的网页如何存入mysql数据库写的一个PHP代码(test.php))
如何将抓取到的网页保存到mysql数据库中
编写的 PHP 代码 (test.php):
如何在mysql数据库中保存这个网页数据?该表是页面字段 1:Pageid |字段 2:页面文本
请求代码
------解决方案--------------------
这不就是插入吗?
值在那里,字段也在那里。 . .
------解决方案--------------------
如果pageid是自增的。也有空缺。
$sql="插入`Page`值 ('','$contents')";
------解决方案--------------------
preg_match_all('/(.*?)/is',$str,$match); //$str 替换为您自己的字符串。
print_r($match);
------解决方案--------------------
PHP 代码
$contents = file_get_contents('a.php');preg_match_all('/()/iUs', $contents, $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);