抓网页_面包网_javaWeb展示

ZC: javase部分的 获取信息的相关代码,看 抓网页_面包网_javaSE 。

1、index.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>
<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="index.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>

<%
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>

 

2、index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>电影信息</title>
    <style type="text/css">
        .movieDetailMsg
        {
            /*width :800px;*/
            height : 100%;
        }
    </style>
    <link rel="stylesheet" href="zctest.css">
    
    <script type="text/javascript">
    
        var g_iPageIdxNow = 0;
    
        // 1、浏览器客户区窗口大小
        // 2、修改css文件信息(内部 / 外部)
        // 3、窗口改变事件
        
        window.onload = function()
        {
            BodyResize();
            
            CssStyle_Test02();
        };
        
        function BodyResize()
        {
            var divMovieContent = document.getElementById("divMovieContent");
            var rtBody = divMovieContent.getBoundingClientRect();
            document.styleSheets[0].cssRules[0].style.width = (rtBody.width-112)+"px";
            if (document.styleSheets[0].cssRules == null)
                console.log("document.styleSheets[0].cssRules == null");
            else
                console.log("document.styleSheets[0].cssRules != null");
            
            if (document.styleSheets[1].cssRules == null)
                console.log("document.styleSheets[1].cssRules == null");
            else
                console.log("document.styleSheets[1].cssRules != null");
        }
        
    // *** *** ***

        // 测试代码
        function CssStyle_Test02()
        {
            CssStyle_Set("zctest.css", ".divVideoState_02", "height", "800px");
            console.log(CssStyle_Get("zctest.css", ".divVideoState_02", "height"));
            
            console.log(CssStyle_Get(null, ".movieDetailMsg", "height"));
        }
        
        // _strCssFilename 传入null时 ==> 操作本文件中的css定义
        // _strCssFilename 传入css文件名称时 ==> 操作外部文件中的css定义
        function CssStyle_Get(_strCssFilename, _strSelectorText, _strPropName)
        {
            console.log("");
            console.log("document.styleSheets.length : "+document.styleSheets.length);
            for (var i=0; i<document.styleSheets.length; i++)
            {
                console.log("==> "+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)
                {
                    // ZC: 属性cssRules/rules的获取,只有在http服务器上的时候才可以获取,浏览器直接打开网页文件的话 是无法访问 这两个属性的 ! !
                    var rules = sheet.cssRules || sheet.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));
                                return rule.style.getPropertyValue(_strPropName);
                            }
                        }
                    }
                } // if (b)
            } // for
            return null;
        } // CssStyle_Get(...)
        
        //*
        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;
        }
        //*/
        
        // _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(...)
    </script>
</head>
<body onresize="BodyResize()">

<div style="background-color:silver; display:-webkit-box;">
    <div>
        <div>
            <input type="button" value="动作片"/>
            <input type="button" value="喜剧片"/>
            <input type="button" value="爱情片"/>
            <input type="button" value="科幻片"/>
            <input type="button" value="恐怖片"/>
        </div>
        <div>
            <input type="button" value="战争片"/>
            <input type="button" value="剧情片"/>
            <input type="button" value="记录片"/>
            <input type="button" value="粤语片"/>
            <input type="button" value="动画电影"/>
        </div>
    </div>
    <div  style="padding-left:50px;">
        <div>
            <input type="text" /><input type="button" value="搜索"/>
        </div>
        <div>
            <input type="button" value="上一页"/>
            <input type="button" value="下一页"/>
        </div>
    </div>
</div>

<div id="divMovieContent">
    <div style="display:-webkit-box; margin-top:1px; margin-bottom:1px;" >
        <div><img src="http://img.mianbao99.com:88/thumb/580360837a4e0.jpg" alt="红色警戒999" /></div>
        <div class="movieDetailMsg">
            <table width="100%" border="1" cellpadding="2" cellspacing="0">
                <tr><td style="width:80px;">评分:</td><td>0.0</td></tr>
                <tr><td>类型:</td><td>悬疑 冒险</td></tr>
                <tr><td>更新时间:</td><td>2016-10-16 19:12:34</td></tr>
                <tr><td>状态:</td><td>BD</td></tr>
                <tr><td>主演:</td><td>卡西·阿弗莱克  切瓦特·埃加福特 安东尼·麦凯 亚伦·保尔</td></tr>
                <tr><td>剧情:</td><td>俄罗斯黑帮头目伊琳娜(凯特·温丝莱特 Kate Winslet 饰)唆使一批腐败的警察进行了一起完美的银行抢劫行动,由于几人均身处警界内部,反侦察能力极强,因此想要查出案件的真相几乎是不可能的事情。然而,几人并不知…</td></tr>
            </table>
        </div>
    </div>
</div>

</body>
</html>

 

3、

4、

5、

 

posted @ 2016-10-20 10:45  CodeHouse  阅读(388)  评论(0编辑  收藏  举报