How crawled pages are stored in MySQL database
Write a PHP code (test.php):
$url = "http://www.baidu.com/";?
$contents = file_get_contents ($url);?
Echo $contents;? ?
How to put crawl of this page data in MySQL database? Table is the page field 1:pageid | Field 2:pagetext
Request Code
------Solution--------------------
Is it just an insert into?
The values are there, the fields also have ...
------Solution--------------------
If the PageID is self-increasing. The vacancy is also available.
$sql = "INSERT INTO ' page ' values (' ', ' $contents ')";
------Solution--------------------
Preg_match_all ('/
(.*?) <\/table>/is ', $str, $match); $str into your own string.
Print_r ($match);
------Solution--------------------
PHP Code
$contents = file_get_contents (' a.php ');p reg_match_all ('/(
<><\ table="">
)/ius ', $contents, $match);// If there are multiple results that need to be matched themselves, the output match array is organized into strings ... $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);
<\>