小功能_mianBao_电影

ZC: 查看 面包网 电影的信息

1、JavaSE (package : mianBao)

  1.1、TmovieMianBao

package mianBao;

import java.util.ArrayList;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.parser.Parser;
import org.jsoup.select.Elements;

import net.sf.json.JSONObject;

//ZC: 修改于 “20161028 16:17”

public class TmovieMianBao
{
    // 站内搜索(搜索界面)
    // http://find.mianbao99.com/vod-search
    // 站内搜索的网址(最后的"AAA"是搜索的内容)
    // http://zhannei.baidu.com/cse/search?s=15458377474113538507&isNeedCheckDomain=1&jump=1&q=AAA
    // ZC疑问:百度有向外提供搜索引擎的服务?通过s来区分不同的用户?
    //    相关教程:http://jingyan.baidu.com/article/7908e85c8f0c36af481ad22d.html
    
    // 动作片:http://www.mianbao99.com/vod-showlist-id-8-order-time-c-3719-p-1.html
    // 喜剧片:http://www.mianbao99.com/vod-showlist-id-9-order-time-c-4058-p-1.html
    // 爱情片:http://www.mianbao99.com/vod-showlist-id-10-order-time-c-2059-p-1.html
    // 科幻片:http://www.mianbao99.com/vod-showlist-id-11-order-time-c-1098-p-1.html
    // 恐怖片:http://www.mianbao99.com/vod-showlist-id-12-order-time-c-3110-p-1.html
    // 战争片:http://www.mianbao99.com/vod-showlist-id-13-order-time-c-736-p-1.html
    // 剧情片:http://www.mianbao99.com/vod-showlist-id-14-order-time-c-8713-p-1.html
    // 纪录片:http://www.mianbao99.com/vod-showlist-id-23-order-time-c-1549-p-1.html
    // 粤语片:http://www.mianbao99.com/vod-showlist-id-27-order-time-c-208-p-1.html
    // 动画电影:http://www.mianbao99.com/vod-showlist-id-31-order-time-c-658-p-1.html
        
    public static void main(String[] args)
    {
    }
    
// ***

    public String FstrJson = null;
    String FstrPagesx = null;
    String FstrAjaxtxt = null;
    
    public int JsonZ()
    {
        JSONObject jsoupObj = JSONObject.fromObject(FstrJson);
        {/*
            Iterator<String> itKeys = jsoupObj.keys();
            while (itKeys.hasNext())
            {
                String strKey = itKeys.next();
                if (! strKey.equalsIgnoreCase("ajaxtxt"))
                {
                    String strValue = jsoupObj.getString(strKey);
                    System.out.println("\n\nValue["+ strKey +"] : ");
                    System.out.println(strValue);
                }
            }
        //*/}
        //*
        if (! jsoupObj.containsKey("ajaxtxt"))
            return -1;
        
        FstrPagesx = jsoupObj.getString("pagesx");
        FstrAjaxtxt = jsoupObj.getString("ajaxtxt");
        Json_pagesx();
        Json_ajaxtxt();
        
        return 0;
    }
    
    public String FstrPageIdxNow = null;
    public String FstrPageIdxTotal = null;
    
    public int Json_pagesx()
    {
        Document doc =  Jsoup.parse(FstrPagesx, "", Parser.xmlParser());
        Element eleLabel = doc.child(0);
        String str = eleLabel.text();
        int iIdx = str.indexOf('/');
        FstrPageIdxNow = str.substring(0, iIdx);
        FstrPageIdxTotal = str.substring(iIdx+1, str.length());
            //System.out.println("当前页序号 : "+FstrPageIdxNow);
            //System.out.println("一共"+FstrPageIdxTotal+"页");

        return 0;
    }
    
    public ArrayList<TinfoMianBaoMovie> FlistMovieInfo = null;
    
    public int Json_ajaxtxt()
    {
        Document doc =  Jsoup.parse(FstrAjaxtxt, "", Parser.xmlParser());
        
        Elements children = doc.children();
        if ( (children == null) || (children.size() == 0) )
        {
            System.out.println("Document has no child .");
            return -1;
        }
        
        if (FlistMovieInfo == null)
            FlistMovieInfo = new ArrayList<TinfoMianBaoMovie>();
        else
            FlistMovieInfo.clear();
        for (int i=0; i<children.size(); i++)
        {
            TinfoMianBaoMovie movieInfo = new TinfoMianBaoMovie();
            FlistMovieInfo.add(movieInfo);
            
            Element eleLi = children.get(i);
            Elements children01 = eleLi.children();
            if (children01 == null)
            {
                System.out.println("<li>["+i+"] has no child .");
                continue;
            }
            else if (children01.size() != 2)
            {
                System.out.println("<li>["+i+"] children's num is not 2 : "+children01.size()+" .");
                continue;
            }
            
            Element eleA = children01.get(0);
            Element eleDiv = children01.get(1);
            Info1_3(movieInfo, eleA);
            Info4_9(movieInfo, eleDiv);
        }
        /*
        for (int i=0; i<FlistMovieInfo.size(); i++)
        {
            TinfoMianBaoMovie movieInfo = FlistMovieInfo.get(i);
            System.out.println(movieInfo.Fstr04_MovieName);
            System.out.println("\t“详情”页面 的链接 : "+movieInfo.Fstr01_XiangQingLink);
            System.out.println("\t图片的链接 : "+movieInfo.Fstr02_PicLink);
            System.out.println("\t评分 : "+movieInfo.Fstr03_Score);
            System.out.println("\t主演 : "+movieInfo.Fstr05_ZhuYan);
            System.out.println("\t类型 : "+movieInfo.Fstr06_Type);
            System.out.println("\t更新时间 : "+movieInfo.Fstr07_UpdateDateTime);
            System.out.println("\t剧情 : "+movieInfo.Fstr08_JuQing);
            System.out.println("\t状态 : "+movieInfo.Fstr09_State);
        }
        //*/
        return 0;
    }
    
    
    public static int Info1_3(TinfoMianBaoMovie _movieInfo, Element _eleA)
    {
        _movieInfo.Fstr01_XiangQingLink = _eleA.attr("href");
        Element eleImg = _eleA.child(0);
        if (eleImg != null)
        {
            _movieInfo.Fstr02_PicLink = eleImg.attr("src");
            // 图片链接,需要做处理
            PicLink(_movieInfo);
        }
        Element eleLabel = _eleA.child(1);
        if (eleLabel != null)
            _movieInfo.Fstr03_Score = eleLabel.text();
        return 0;
    }
    
    public static int PicLink(TinfoMianBaoMovie _movieInfo)
    {
        // http://img.mianbao99.com:88/thumb/580360837a4e0.jpg
        String strUrl = "img.mianbao99.com:88";
        
        int iIdx01 = _movieInfo.Fstr02_PicLink.indexOf("//");
        int iIdx02 = _movieInfo.Fstr02_PicLink.indexOf('/', iIdx01+2);
        if (iIdx02 <= iIdx01)
            return -1;
        String str01 = _movieInfo.Fstr02_PicLink.substring(0, iIdx01+2);
        //String str02 = _movieInfo.Fstr02_PicLink.substring(iIdx01+2, iIdx02);
        String str03 = _movieInfo.Fstr02_PicLink.substring(iIdx02);
//            System.out.println(iIdx01+" --> "+iIdx02);
//            System.out.println("\t"+str01);
//            System.out.println("\t"+str02);
//            System.out.println("\t"+str03);
        _movieInfo.Fstr02_PicLink = str01 + strUrl + str03;
            //System.out.println(_movieInfo.Fstr02_PicLink);
        return 0;
    }
    
    public static int Info4_9(TinfoMianBaoMovie _movieInfo, Element _eleDiv)
    {
        {
            Element eleH5 = _eleDiv.child(0);
                Element eleA = eleH5.child(0);
                    _movieInfo.Fstr04_MovieName = eleA.text();
        }
        {
            Element eleP_ZhuYan = _eleDiv.child(1);
            _movieInfo.Fstr05_ZhuYan = "";
                Elements chiledren = eleP_ZhuYan.children();
                    for (int i=1; i<chiledren.size(); i++)
                    {
                        Element child = chiledren.get(i);
                        _movieInfo.Fstr05_ZhuYan += child.text();
                        if (i != (chiledren.size()-1))
                            _movieInfo.Fstr05_ZhuYan += " ";
                    }
        }
        {
            Element eleP_Type = _eleDiv.child(2);
            _movieInfo.Fstr06_Type = "";
                Elements chiledren = eleP_Type.children();
                    for (int i=1; i<chiledren.size(); i++)
                    {
                        Element child = chiledren.get(i);
                        _movieInfo.Fstr06_Type += child.text();
                        if (i != (chiledren.size()-1))
                            _movieInfo.Fstr06_Type += " ";
                    }
        }
        {
            Element eleP_UpdateDateTime = _eleDiv.child(3);
            _movieInfo.Fstr07_UpdateDateTime = eleP_UpdateDateTime.ownText();
            
        }
        {
            Element eleP_JuQing = _eleDiv.child(4);
            _movieInfo.Fstr08_JuQing = eleP_JuQing.ownText();
        }
        {
            Element eleP_State = _eleDiv.child(5);
            String str = eleP_State.ownText();
            char c = (char)160;
            str = str.replace(c, ' ');
            _movieInfo.Fstr09_State = str;
        }
        return 0;
    }

}

  1.2、TinfoMianBaoMovie

package mianBao;

//面包网 的电影的信息
public class TinfoMianBaoMovie
{    
    public String Fstr01_XiangQingLink = null; // “详情”页面 的链接
    public String Fstr02_PicLink = null; // 图片的链接
    public String Fstr03_Score = null; // 面包网 的对本电影的评分
    public String Fstr04_MovieName = null; // 电影名称
    public String Fstr05_ZhuYan = null; // 主演(们)的姓名
    public String Fstr06_Type = null; // 电影的类型(s)
    public String Fstr07_UpdateDateTime = null; // 更新时间(这是网站更新本电影的时间,并非电影的上映时间[这个要到影片的“详情”页面里面去看])
    public String Fstr08_JuQing = null; // (可能不完整的)剧情介绍
    public String Fstr09_State = null; // 影片的状态(暂无地址 /BD/HD/TC 等)
}

 

2、JavaWeb

  2.1、mianBao.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="utf-8"%>
<%@page import="mianBao.*, z_utils.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- 修改于 “20161028 16:26” -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta charset="UTF-8"> <!-- for HTML5 -->
<title>电影信息JSP</title>

    <style type="text/css">
        .movieDetailMsg
        {
        }
        .moviePic
        {
            width:112px;
        }
        
        table
        {
            background-color: white;
            padding-left: 5px;
        }
        table tr:nth-child(2)
        {
            background-color: silver;
        }
        table tr:nth-child(5)
        {
            background-color: silver;
        }
        table tr:last-child td/*<tr/>是不会绘制border的,只有对<td/>设置 才有效*/
        {
            border-top: 1px solid black;
        }
        
        #back-to-top{
            position:fixed;
            right: 30px;
            bottom: 100px;
            display: block;
            z-index: 999999;
        }
        #back-to-top a{
            width: 50px;
            height: 50px;
            display: block;
            overflow: hidden;
            text-indent: -999px;
            /*background: url(../images/back-to-top.gif) 0 0 no-repeat #2d2d2d;*/
            background: url(http://www.mianbao99.com/static/images/back-to-top.gif) 0 0 no-repeat #2d2d2d;/*ZC: 很神奇的gif操作,需要学习一下*/
            border-radius: 25px;
        }
        #back-to-top a:hover{
            background-position: -50px 0;
            background-color: #f60;
        }
    </style>
    
    <script type="text/javascript">
    
        // 1、浏览器客户区窗口大小
        // 2、修改css文件信息(内部 / 外部)
        // 3、窗口改变事件
        
        window.onload = function()
        {
            BodyResize();
        };
        
        window.onscroll = function()
        { 
//             var scroll = document.documentElement.scrollTop || document.body.scrollTop;
//             var divPiao = document.getElementById("divPiao");
//             divPiao.style.top = (document.body.scrollTop + window.screen.availHeight - 200) +"px";
//             //divPiao.style.top = (document.body.scrollTop + document.body.offsetHeight - 200) +"px";
//             divPiao.style.left = (document.body.scrollWidth - 100) +"px";
//             console.log(window.screen.availWidth+" , "+window.screen.availHeight);
//             console.log(document.body.clientWidth+" , "+document.body.clientHeight);
        }
        
        function BodyResize()
        {
            var divMovieContent = document.getElementById("divMovieContent");
            var rtBody = divMovieContent.getBoundingClientRect();
            CssStyle_Set(null, ".movieDetailMsg", "width", (rtBody.width-112)+"px");
        }
        
        function ClickDivBack2Top()
        {
            document.body.scrollTop = 0;
        }
        
    // *** *** ***
        
    // *** 操作 css定义 begin
        // _strCssFilename 传入null时 ==> 操作本文件中的css定义
        // _strCssFilename 传入css文件名称时 ==> 操作外部文件中的css定义
        function CssStyle_Set(_strCssFilename, _strSelectorText, _strPropName, _strPropValue)
        {
            //console.log("");
            //console.log("document.styleSheets.length : "+document.styleSheets.length);
            for (var i=0; i<document.styleSheets.length; i++)
            {
                var sheet = document.styleSheets[i]; // CCCStyleSheet类型
                //console.log("sheet.href : "+sheet.href);
                
                var b = false;
                if (_strCssFilename == null)
                {
                    if (sheet.href == null)
                        b = true;
                }
                else
                {
                    if (sheet.href != null)
                    {
                        var strRtnFilename = Href_Filename(sheet.href).toLowerCase();
                        //console.log("strRtnFilename : "+strRtnFilename);
                        if (strRtnFilename == _strCssFilename.toLowerCase())
                            b = true;
                    }
                }
                
                if (b)
                {
                    var rules = sheet.cssRules || cssRules.rules;
                    if (rules.length > 0)
                    {
                        for (var j=0; j<rules.length; j++)
                        {
                            var rule = rules[j];
                            if (rule.selectorText.toLowerCase() == _strSelectorText.toLowerCase())
                            {
                                //console.log("rule : "+rule+" , rule.style : "+rule.style);
                                //console.log(rule.style.getPropertyValue(_strPropName));
                                rule.style.setProperty(_strPropName, _strPropValue);
                            }
                        }
                    }
                } // if (b)
            } // for
            return null;
        } // CssStyle_Set(...)
        
        function Href_Filename(_strCssHref)
        {
            // 返回的是文件名(如传入的是"http://localhost:8080/Html5_Video_Simplest/Play.css",那么返回的就是"Play.css")
            var iInLen = _strCssHref.length;
            if (iInLen <= 0)
                return null;
            for (var i=(iInLen - 1); i>=0; i--)
            {
                if (_strCssHref.charAt(i) == '/')
                {
                    if (i == (iInLen - 1))
                        return null;
                    return _strCssHref.slice(i+1, iInLen);
                }
            }
            return null;
        }
    // *** 操作 css定义 end
<%
String strRequestPageIdx = request.getParameter("requestPageIdx");
if (strRequestPageIdx == null)
{%>
    var g_iPageIdxNow = 1;
<%}
else
{%>
    var g_iPageIdxNow = <%=strRequestPageIdx%>;
<%}
//动作片、喜剧片、爱情片、科幻片、恐怖片、战争片、剧情片、记录片、粤语片、动画电影
// 电影类型,从0开始计数
String strRequestType = request.getParameter("requestType");
if (strRequestType == null)
{%>
    var g_iMovieType = 0;
<%}
else
{%>
    var g_iMovieType = <%=strRequestType%>;
<%}%>

        function ClickMovieType(_event)
        {
            var btn = _event.target;
            //console.log(_event.target.value);
            if (btn.value == "动作片")
                g_iMovieType = 0;
            else if (btn.value == "喜剧片")
                g_iMovieType = 1;
            else if (btn.value == "爱情片")
                g_iMovieType = 2;
            else if (btn.value == "科幻片")
                g_iMovieType = 3;
            else if (btn.value == "恐怖片")
                g_iMovieType = 4;
            else if (btn.value == "战争片")
                g_iMovieType = 5;
            else if (btn.value == "剧情片")
                g_iMovieType = 6;
            else if (btn.value == "记录片")
                g_iMovieType = 7;
            else if (btn.value == "粤语片")
                g_iMovieType = 8;
            else if (btn.value == "动画电影")
                g_iMovieType = 9;
            
            g_iPageIdxNow = 1;
            PageGoto(g_iMovieType, 1);
        }
        
        function ClickNextPrev(_bNext)
        {
            if (_bNext)
                g_iPageIdxNow ++;
            else
            {
                if (g_iPageIdxNow <= 1)
                    g_iPageIdxNow = 1;
                else
                    g_iPageIdxNow --;
            }
            PageGoto(g_iMovieType, g_iPageIdxNow);
        }
        
        function PageGoto(_iMovieType, _iPageIdx)
        {
            var strUrl = null;
            if (g_iMovieType == 0)
                strUrl = "http://ajax.mianbao99.com/vod-showlist-id-8-order-time-c-3719-p-";//1.html
            else if (g_iMovieType == 1)
                strUrl = "http://ajax.mianbao99.com/vod-showlist-id-9-order-time-c-4058-p-";//1.html
            else if (g_iMovieType == 2)
                strUrl = "http://ajax.mianbao99.com/vod-showlist-id-10-order-time-c-2059-p-";//1.html
            else if (g_iMovieType == 3)
                strUrl = "http://ajax.mianbao99.com/vod-showlist-id-11-order-time-c-1098-p-";//1.html
            else if (g_iMovieType == 4)
                strUrl = "http://ajax.mianbao99.com/vod-showlist-id-12-order-time-c-3110-p-";//1.html
            else if (g_iMovieType == 5)
                strUrl = "http://ajax.mianbao99.com/vod-showlist-id-13-order-time-c-736-p-";//1.html
            else if (g_iMovieType == 6)
                strUrl = "http://ajax.mianbao99.com/vod-showlist-id-14-order-time-c-8713-p-";//1.html
            else if (g_iMovieType == 7)
                strUrl = "http://ajax.mianbao99.com/vod-showlist-id-23-order-time-c-1549-p-";//1.html
            else if (g_iMovieType == 8)
                strUrl = "http://ajax.mianbao99.com/vod-showlist-id-27-order-time-c-208-p-";//1.html
            else if (g_iMovieType == 9)
                strUrl = "http://ajax.mianbao99.com/vod-showlist-id-31-order-time-c-658-p-";//1.html
                
            window.location.href="mianBao.jsp?requestUrl="+strUrl+(""+g_iPageIdxNow)+".html&requestPageIdx="+g_iPageIdxNow+"&requestType="+g_iMovieType;
        }
        
        function Search()
        {
            var textSearch = document.getElementById("textSearch");
            if (textSearch.value)
            {
                var strUrl01 = "http://zhannei.baidu.com/cse/search?s=15458377474113538507&isNeedCheckDomain=1&jump=1&q=";
                window.open(strUrl01+textSearch.value); //在另外新建窗口中打开窗口
            }
        }
        
        function KeyDown_Search(_event)
        {
            if (_event.keyCode == 13)
            {
                 //_event.returnValue = false;
                 //_event.cancel = true;
                 Search();
            }
        }
    </script>
</head>

<body onresize="BodyResize()">

<div style="background-color:silver; display:-webkit-box;">
    <div>
        <div>
            <input type="button" value="动作片" onclick="ClickMovieType(event)" />
            <input type="button" value="喜剧片" onclick="ClickMovieType(event)"/>
            <input type="button" value="爱情片" onclick="ClickMovieType(event)"/>
            <input type="button" value="科幻片" onclick="ClickMovieType(event)"/>
            <input type="button" value="恐怖片" onclick="ClickMovieType(event)"/>
        </div>
        <div>
            <input type="button" value="战争片" onclick="ClickMovieType(event)"/>
            <input type="button" value="剧情片" onclick="ClickMovieType(event)"/>
            <input type="button" value="记录片" onclick="ClickMovieType(event)"/>
            <input type="button" value="粤语片" onclick="ClickMovieType(event)"/>
            <input type="button" value="动画电影" onclick="ClickMovieType(event)"/>
        </div>
    </div>
    <div  style="padding-left:50px;">
        <div>
            <input id="textSearch" type="text" onkeydown="KeyDown_Search(event)"/><input type="button" value="搜索" onclick="Search()" />
        </div>
        <div>
            <input type="button" value="上一页" onclick="ClickNextPrev(false)" />
            <input type="button" value="下一页" onclick="ClickNextPrev(true) "/>
        </div>
    </div>
</div>

<%
// System.out.println("request.getRequestURI() : "+request.getRequestURI());
// System.out.println("request.getRequestURL() : "+request.getRequestURL());
// System.out.println("request.getQueryString() : "+request.getQueryString());

String strRequestUrl = request.getParameter("requestUrl");
if (strRequestUrl == null)
    strRequestUrl = "http://ajax.mianbao99.com/vod-showlist-id-8-order-time-c-3719-p-1.html";
//System.out.println(strRequestUrl);
String strHtml = TzHttpClient.GetZ(strRequestUrl);
//System.out.println(strHtml);

TmovieMianBao movie = new TmovieMianBao();
movie.FstrJson = strHtml;
movie.JsonZ();

String[] strsMovieType = {"动作片", "喜剧片", "爱情片", "科幻片", "恐怖片", "战争片", "剧情片", "记录片", "粤语片", "动画电影"};
int iMovieType = 0;
if (strRequestType != null)
    iMovieType = Integer.parseInt(strRequestType);
String strLocation = "当前位置 : "+strsMovieType[iMovieType]+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;第["+movie.FstrPageIdxNow+"]页 / 共["+movie.FstrPageIdxTotal+"]页";
%>

<div>
    <%=strLocation%>
</div>
<div style="background-color: black; height:3px;"></div>

<div id="divMovieContent">
<%    
    if ( (movie.FlistMovieInfo != null) && (movie.FlistMovieInfo.size() > 0) )
    {
        for (int i=0; i<movie.FlistMovieInfo.size(); i++)
        {
            TinfoMianBaoMovie info = movie.FlistMovieInfo.get(i);
            //out.println(info.Fstr04_MovieName);
            //System.out.println(info.Fstr04_MovieName);
            //info.Fstr01_XiangQingLink
%>
    <div style="display:-webkit-box; margin-top:3px; margin-bottom:3px;" >
        <div>
            <a href="<%=info.Fstr01_XiangQingLink%>" target="_blank">
                <img class="moviePic" src="<%=info.Fstr02_PicLink%>" alt="<%=info.Fstr04_MovieName%>" />
                <%
                //System.out.println(info.Fstr02_PicLink);
                %>
            </a>
        </div>
        <div class="movieDetailMsg">
            <table width="100%" border="0" cellpadding="2" cellspacing="0">
                <tr><td style="width:80px;">影片名:</td><td><a href="<%=info.Fstr01_XiangQingLink%>" target="_blank"><%=info.Fstr04_MovieName%></a></td></tr>
                <tr><td>评分:</td><td><%=info.Fstr03_Score%></td></tr>
                <tr><td>类型:</td><td><%=info.Fstr06_Type%></td></tr>
                <tr><td>更新时间:</td><td><%=info.Fstr07_UpdateDateTime%></td></tr>
                <tr><td>状态:</td><td><%=info.Fstr09_State%></td></tr>
                <tr><td>主演:</td><td><%=info.Fstr05_ZhuYan%></td></tr>
                <tr><td>剧情:</td><td><%=info.Fstr08_JuQing%></td></tr>
            </table>
        </div>
    </div>
    <div style="background-color: black; height:3px;"></div>
        
<%
        }
    }
%>

</div>
<!-- 
<div id="divPiao" style="background-color: pink; width:30px; height:20px; position: fixed; right: 20px; bottom: 100px; z-index: 999999;" onclick="ClickDivPiao()">
    <label>TOP</label>
</div>
 -->
<div id="back-to-top">
    <a href=# target="_self">Back to Top</a>
</div>
    
</body>
</html>

 

3、

 

posted @ 2016-10-28 16:19  CodeHouse  阅读(2109)  评论(0编辑  收藏  举报