PHP movie Crawlers (2)

Source: Internet
Author: User

After learning someone else's reptile, one of their own, is also a review of the use of PHP

Let's take advantage of Simple_html_dom's collection of data instances, which is a PHP library that is easy to get started with.
Simple_html_dom can help us to parse HTML documents with PHP very well. This PHP wrapper class makes it easy to parse HTML documents and manipulate HTML elements (php5+ or more)

: Https://github.com/samacs/simple_html_dom

or http://paopaotv.com/tv-type-id-5-pg-1.html this letter page 1 <? PHP

2Set_time_limit (0);3Header"Content-type:text/html;charset=utf-8");4Require'.. /.. /web crawler/simple_html_dom-master/simple_html_dom.php');5Require'./config.php';6$DBNA ="crawler";7 mysql_select_db ($DBNA, $link);8 //get HTML Data conversion objects9$html = file_get_html ('http://paopaotv.com/tv-type-id-5-pg-1.html');Ten  One //A -Z alphabetical list each piece of data is class=letter-focus=item within the Id=letter-focus div . A //within the DL tag, use the Find method to locate the -$ListData = $html->find ("#letter-focus. Letter-focus-item"); - //$listData an Array object the$count =0; - foreach($ListData as$key =$EachLetterData) { -$LetterData = $EachLetterData->find ("DD a"); -     foreach($LetterData as$Letterinfo) { +$count + +; -         //Movie Name +$filmName = $Letterinfoplaintext; A         //echo "<br/>"; at         //Movie Address -$FILMURL = $Letterinfohref; -$FILMURL ="http://www.paopaotv.com". $filmUrl; -         //echo "<br/>"; -         //the address content of a movie -$filmInfo =file_get_html ($FILMURL); in         //The information you are looking for -$filmDetail = $filmInfo->find (". Info DL"); to         foreach($filmDetail as$film) { +$info = $film->find ("DD"); -             foreach($info as$childinfo) { the$row [] = $childinfoplaintext; *             } $         }Panax Notoginseng$sql ="INSERT INTO Movie2 (name,url,actor,status,form,location,label,director,time,year) VALUES (' {$filmName} ', ' {$ Filmurl} ', -         '{$row [0]}','{$row [1]}','{$row [2]}','{$row [3]}','{$row [4]}','{$row [5]}','{$row [6]}','{$row [7]}')"; theEcho"<pre>"; +Echo $sql."<br/>"; A mysql_query ($sql);  the$row =NULL; +         //if ($count ==3) {goto A;} -Echo"<br/>"; $     } $     //echo "<br/>"; - } -A:
About the problem you are experiencing:
Character encoding problem, uft-8 again pit me, then in config.php added set names uft8 to solve, the problem is sometimes added to the spirit, sometimes there is no ... Rookie Quotes

PHP movie Crawlers (2)

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.