微现场IM互动
标题:
六、电影排行榜
[打印本页]
作者:
eoiioe
时间:
2014-2-2 13:50
标题:
六、电影排行榜
微信电影排行榜
( z. D% c" [9 C/ I; O# r
在网上找了很久都没找到一个电影api,豆瓣电影api可以,可是要认证地址,麻烦,于是就找了一个网站,实时抓取数据了,由于我抓取的数据没有直接保存进数据库,so,过个过程会有点慢.先上效果图
6 |5 _0 G% r' m
5 G# h% Y6 Q, q5 f9 `0 [1 w0 P& a
% B" Z9 Q. t( H8 g, U9 W; l4 w4 r
1、入口界面
/ Q, d/ ]8 v3 o
* G% Z( N" c, K, R3 U' a" V, z: h
登录/注册后可看大图
3 e/ E+ T* m7 {% Q
# n+ u' w! i. f- X9 S
2、排行榜页面
& I8 _/ n) ~0 P8 f
! m8 h+ V/ H( i \) S9 j
登录/注册后可看大图
9 m2 @, ]2 Z. ^2 T5 x
) A* Z, U! a) A4 ] k. q0 X' Y( E
3、今日排行(输入3.1)
) K+ h! O$ o8 N, P, Q: }
- i9 W3 [) m) d; q
登录/注册后可看大图
' O5 ]# B7 M- S% L1 ?' R
0 y6 V# y/ }3 A* R
4、北美票房(3.2)
- o3 u; V' p6 c- `9 Q1 T
' C/ A9 ?6 T! v' b
登录/注册后可看大图
7 `; F8 E0 L6 e/ g- O( d
! H) r# s' f) n; C, O0 w2 V
5、香港票房 3.3
* y! j! S5 X, j$ q; e$ B) |' F6 K
. Q$ K( m1 _, M6 c9 ^8 }
登录/注册后可看大图
2 g) c/ A. G4 l6 A1 d
( S. o7 B, }/ b7 F
6、电影收视榜 3.4
/ z, q* B. U; G& g
& |) b Q. D( S! w5 c8 j' t
登录/注册后可看大图
# t& `% T0 p1 r$ @' x2 d
# C4 V4 `: W5 Q4 X' {
7、电视收视榜 3.5
) ~" V/ c! B& z6 c
7 d [9 v# K" P! n3 Q+ S
登录/注册后可看大图
8 x6 k$ B7 V( S0 w7 k, z3 }
* |1 s1 G$ @' I- c; |
数据抓取来源:
http://data.entgroup.cn
,使用到了simple_html_dom html解析库,代码如下
//----------------------------------------------------------------电影排行榜开始------------
//抓取
http://data.entgroup.cn/
电影数据
private
function
_movie_comm
(
$url
,
$param
=
""
,
$title
=
""
){
//设置头内容
$length
=
empty
(
$param
)?
0
:
19
;
//好吧,我这里写死了长度..
$header
=
array
(
"Accept-Encoding:gzip,deflate,sdch"
,
"Accept-Language:zh-CN,zh;q=0.8"
,
"Content-Length
length"
,
"Content-Type:application/json; charset=UTF-8"
,
"Host:data.entgroup.cn"
,
);
$reArr
=
http
(
$url
,
$param
,
"
OST"
,
$header
);
Log
::
write
(
"url ->$url , param =$param ,head =>"
.
print_r
(
$header
,
true
));
$data
=
json_decode
(
$reArr
);
if
(
empty
(
$data
)){
return
array
(
"未找到数据,请检查网络或稍后再试试看。"
,
"text"
);
}
$html
=
$data
->
d
;
$preg2
=
'/<a .*?>(.*?)<\/a>/is'
;
//(?!<img)//取出所有信息(包括第一张图片)
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
){
//第一张是图片
$datas
[
$i
][]
=
$title
;
$datas
[
$i
][]
=
""
;
$src_path
=
$data
[
$i
];
$pattern
=
"/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg]))[\'|\"].*?[\/]?>/"
;
//抓取图片
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
][]
=
"小助手:回复 ? 进入到主菜单。"
;
$datas
[
$count
][]
=
""
;
$datas
[
$count
][]
=
""
;
$datas
[
$count
][]
=
""
;
return
array
(
$datas
,
"news"
);
}
//今日票房
public
function
get_today
(){
return
$this
->
_movie_comm
(
"http://data.entgroup.cn/BoxOffice/movieData/Movie.aspx/BindDayList"
,
"今日票房"
);
}
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
;
}
//北美票房
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
,
"北美票房"
);
}
//香港票房
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
,
"香港票房"
);
}
//电影收视,电视收视共同
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
){
//第一张是图片
$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
][]
=
"小助手:回复 ? 进入到主菜单。"
;
$datas
[
$i
][]
=
""
;
$datas
[
$i
][]
=
""
;
$datas
[
$i
][]
=
""
;
return
array
(
$datas
,
"news"
);
}
//电影收视榜
public
function
get_movie
(){
$url
=
"http://data.entgroup.cn/ratings/film"
;
$match
=
".person .trs a"
;
//查找指定的所有a标签数据
return
$this
->
_send_movie_comm
(
$url
,
$match
,
"电影收视榜"
,
"movie.jpg"
);
}
//电视收视榜
public
function
get_tv
(){
$url
=
"http://data.entgroup.cn/ratings/tv"
;
$match
=
".person .trs a"
;
//查找指定的所有a标签数据
return
$this
->
_send_movie_comm
(
$url
,
$match
,
"电视收视榜"
,
"tv.jpg"
);
}
//----------------------------------------------------------------电影排行榜结束------------
t* C( H/ C6 y$ ?2 z" X8 L0 a
" Z$ n {8 ^& K2 Q+ w
欢迎光临 微现场IM互动 (https://www.qnwall.com/)
Powered by Discuz! X3.4