A _php example of "sequel" of a Simple collection data warehousing program based on PHP

Source: Internet
Author: User

In the last article, we have collected a list of news page data, the next thing to do is to read from the database required to collect the URL, the page crawl on the line

Create a new content table

However, it is important to note that the collection URL can not be used to increase the number of methods to collect, because the data table may be intermittent ID, such as id=9,id=11, when the collection of id=10, the URL is blank, which may result in the collection of empty fields.

One of the techniques used here is the database query statement, when we collect the first data, to determine whether there are more than this ID ID number in the database, if there is, read a, query information repeat the above work.

The specific code is as follows:

<?php
  
  include_once ("conn.php");
  $id = (int) $_get[' id '];
  $sql = "SELECT * from list where id= $id";
  $result =mysql_query ($sql);
  $row =mysql_fetch_array ($result);//obtain the corresponding URL address
  $content =file_get_contents ($row [' url ']);
  $pattern = "/<dd class=\" Datawrap\ "> (. *) <\/dd>/ius";
  Preg_match ($pattern, $content, $info)//get content to store info
  echo $title = $row [1]. " <br/> ";
  echo $content = $info [0]. "  
 

This way we want the news content on the collection, and then only need some of the data to organize the style of the line.

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.