fold all codes

校内电影资源好,但页面看着头疼,php抓

框架写的太久,没注释,用的时候有的需要回去重看一遍。

E:\htdocs\controller\Twt.php
 1 <?php
2 class C_Twt
3 {
4 public function movie()
5 {
6 $uriLogin = 'http://www.twt.edu.cn/movie/logincp.php';
7 $uriDetail = 'http://www.twt.edu.cn/movie/?/detail_id-%d.htm';
8 $uriDownload = 'http://www.twt.edu.cn/movie/?/download_id-%d.htm';
9
10 $curl = Q('QCurl');
11 $ret = $curl->post($uriLogin, array(
12 'username' => 'hylent',
13 'password' => '',
14 'action' => 'login',
15 'login' => '登录',
16 ));
17
18 $id = (int) Q('QRequest')->param;
19 if ($id < 1)
20 {
21 $body = <<<EOB
22 movie id:
23 <input type="text" id="id" />
24 <button id="btn">get</button>
25 <div id="result"></div>
26 <script>
27 $('#btn').click(function(){
28 var id = parseInt($('#id').val());
29 if (!id || id < 1)
30 {
31 alert('err id');
32 return;
33 }
34 $.getJSON('/twt/movie/'+id, function(d){
35 if (!d.ok)
36 {
37 alert('err ret');
38 return;
39 }
40 $('#result').empty();
41 $.each(d.data, function(k, v){
42 $('#result').append('<a href="'+v.uri+'">'+v.title+'</a>');
43 });
44 });
45 });
46 </script>
47 EOB;
48 QV(new QVHtml())->javascript(array(
49 '/public/javascript/jquery-1.7.1.min.js'))->body($body);
50 return;
51 }
52
53 $str = $curl->get(sprintf($uriDetail, $id));
54
55 $arr = null;
56 $arr2 = null;
57 $pat = '/<a\shref="\?\/download_id-(\d+)\.htm"\starget="_blank">([^<>]+)<\/a>/';
58 $pat2 = '/height="100px"><a\shref="([^<>]*)">/';
59 $n = preg_match_all($pat, $str, $arr);
60
61 $ret = array();
62 for ($i = 0; $i < $n; $i++)
63 {
64 $tmp = array();
65 $tmp['id'] = $arr[1][$i];
66 $tmp['title'] = mb_convert_encoding($arr[2][$i], 'utf8', 'gbk');
67
68 $str2 = $curl->get(sprintf($uriDownload, $tmp['id']));
69 preg_match_all($pat2, $str2, $arr2);
70 $tmp['uri'] = $arr2[1][0];
71
72 $ret[] = $tmp;
73 }
74
75 QV(new QVJson(array('ok' => 1,
76 'data' => $ret)));
77 }
78 }

 

posted @ 2012-03-09 21:32  hylent  阅读(329)  评论(0编辑  收藏  举报