6. movie rankings

Source: Internet
Author: User
Provides various official and user-released code samples for reference.
I haven't found a movie api on the Internet for a long time. I can use a Douban movie api, but I want to authenticate the address. So I found a website and captured data in real time, since the data I captured is not directly saved in the database, so will be a little slow. first


1. portal interface


2. Ranking page


3. ranking today (input 3.1)


4. North America box office (3.2)


5. Hong Kong box office 3.3


6. Movie viewing list 3.4


7. TV viewing list 3.5


Data capture Source: http://data.entgroup.cn, using simple_html_dom html Parsing Library, the Code is as follows // ------------------------------------------------------------------ Movie rankings start ------------
// Capture movie data at http://data.entgroup.cn/
Private function _ movie_comm ($ url, $ param = "", $ title = ""){
// Set the header content
$ Length = empty ($ param )? 0: 19; // Well, I am writing dead length here ..
$ Header = array (
"Accept-Encoding: gzip, deflate, sdch ",
"Accept-Language: zh-CN, zh; q = 0.8 ",
"Content-Length: $ length ",
"Content-Type: application/json; charsets = UTF-8 ",
"Host: data.entgroup.cn ",
);
$ ReArr = http ($ url, $ param, "POST", $ header );
Log: write ("url-> $ url, param = $ param, head =>". print_r ($ header, true ));
$ Data = json_decode ($ reArr );
If (empty ($ data )){
Return array ("no data found. Check the network or try again later. "," Text ");
}
$ Html = $ data-> d;
$ Preg2 = '/(.*?) <\/A>/is ';//(?! Preg_match_all ($ preg2, $ html, $ match );
$ Data = $ match [1];
$ Count = count ($ data );
$ Datas = array ();
For ($ I = 0; $ I <$ count; $ I ++ ){
If ($ I> 8 ){
Break;
}
If ($ I = 0) {// the first image is
$ Datas [$ I] [] = $ title;
$ Datas [$ I] [] = "";
$ Src_path = $ data [$ I];
$ Pattern = "/<[img | IMG]. *? Src = [\ '| \ "] (. *? (? : [\. Gif | \. jpg]) [\ '| \ "]. *? [\/]?> /"; // Capture an image
Preg_match_all ($ pattern, $ src_path, $ image_match );
$ Datas [$ I] [] = $ image_match [1] [0];
$ Datas [$ I] [] = "";
} Else {

$ Datas [$ I] [] = "{$ I},". $ data [$ I];
$ Datas [$ I] [] = "";
$ Datas [$ I] [] = "";
$ Datas [$ I] [] = "";
}
}
$ Datas [$ count] [] = "reply? Go to the main menu. ";
$ Datas [$ count] [] = "";
$ Datas [$ count] [] = "";
$ Datas [$ count] [] = "";

Return array ($ datas, "news ");
}

// Today's box office
Public function get_today (){
Return $ this-> _ movie_comm ("http://data.entgroup.cn/BoxOffice/movieData/Movie.aspx/BindDayList", "Today's box office ");
}

Private function _ get_week_id ($ find_id ){
Import ("@. ORG. simple_html_dom", null, ". php ");
$ Html = file_get_html ("http://data.entgroup.cn/boxoffice/oversea ");
$ Ele = $ html-> find ("$ find_id option", 0 );
Return $ ele? $ Ele-> value: null;
}
// North America box office
Public function get_na (){
$ WeekId = $ this-> _ get_week_id ("# week2 ");
$ Param = "{'weekid': '$ weekId '}";
Return $ this-> _ movie_comm ("http://data.entgroup.cn/BoxOffice/movieData/oversea.aspx/BindUSAList", $ param, "North America box office ");
}

// Hong Kong box office
Public function get_hk (){
$ WeekId = $ this-> _ get_week_id ("# week1 ");
$ Param = "{'weekid': '$ weekId '}";
Return $ this-> _ movie_comm ("http://data.entgroup.cn/BoxOffice/movieData/oversea.aspx/BindHongKongList", $ param, "Hong Kong Box Office ");
}

// Movie and TV views
Private function _ send_movie_comm ($ url, $ match, $ title, $ image ){
Import ("@. ORG. simple_html_dom", null, ". php ");
$ Html = file_get_html ($ url );
$ OK _datas = $ html-> find ($ match );
$ Datas = array ();
$ I = 0;
Foreach ($ OK _datas as $ row ){
If ($ I> 9 ){
Break;
}
If ($ I = 0) {// the first image is
$ Datas [$ I] [] = $ title;
$ Datas [$ I] [] = "";
$ Datas [$ I] [] = "http://www.aidemofang.com.img.800cdn.com/public/home/images/#image ";
$ Datas [$ I] [] = "";
} Else {

$ Datas [$ I] [] = "{$ I},". trim ($ row-> plaintext );
$ Datas [$ I] [] = "";
$ Datas [$ I] [] = "";
$ Datas [$ I] [] = "";
}
$ I ++;
}
$ Datas [$ I] [] = "reply? Go to the main menu. ";
$ Datas [$ I] [] = "";
$ Datas [$ I] [] = "";
$ Datas [$ I] [] = "";

Return array ($ datas, "news ");
}
// Movie rating list
Public function get_movie (){
$ Url = "http://data.entgroup.cn/ratings/film ";
$ Match = ". person. trs a"; // search for all specified a tag data
Return $ this-> _ send_movie_comm ($ url, $ match, "movie viewlist", "movie.jpg ");
}

// TV rating list
Public function get_ TV (){
$ Url = "http://data.entgroup.cn/ratings/ TV ";
$ Match = ". person. trs a"; // search for all specified a tag data
Return $ this-> _ send_movie_comm ($ url, $ match, "TV rating list", "TV .jpg ");
}

// ------------------------------------------------------------------ The film ranking is over ------------


Casual beans: http://www.xiuxiandou.com

AD: truly free, domain name + VM + enterprise mailbox = 0 RMB

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.