How crawled pages are stored in MySQL database

Source: Internet
Author: User
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);
    
  • <\>

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.