Home > Backend Development > PHP Tutorial > 抓取的网页怎么存入mysql数据库

抓取的网页怎么存入mysql数据库

WBOY
Release: 2016-06-13 13:42:19
Original
945 people have browsed it

抓取的网页如何存入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('/

(.*?)/is',$str,$match); //$str换成你自己的字符串。
print_r($match);
------解决方案--------------------
PHP code

$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.>
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template