Beispiel #1
0
        public string LoadNewlist(HttpContext context)
        {
            var    fbsj        = "00";
            var    gzgw        = context.Request["work"];
            var    ssldbm      = context.Request["place"];
            var    page        = context.Request["page"];
            string url         = string.Format(@"http://fjlylm.com/vizpxx.asp?ssldbm={0}&gzgw={1}&fbsj={2}&page={3}", ssldbm, gzgw, fbsj, page);
            string content     = CommonUtility.HttpUtility.Get(url, System.Text.Encoding.Default);
            int    iTableStart = content.IndexOf("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"95%\" class=\"pix9\">", 0);

            if (iTableStart < 1)
            {
                return("");
            }
            int iTableEnd = content.IndexOf("</table>", iTableStart);

            if (iTableEnd < 1)
            {
                return("");
            }
            string strWeb = content.Substring(iTableStart, iTableEnd - iTableStart);

            #region Tr列表

            //生成HtmlDocument
            HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml(strWeb);
            List <MyLink> myLinkList = new List <MyLink>();
            foreach (HtmlNode trNode in doc.DocumentNode.SelectNodes("//tr"))
            {
                if (!trNode.InnerHtml.Contains("font"))
                {
                    var mylink = new MyLink();
                    foreach (HtmlNode tdNode in trNode.ChildNodes)
                    {
                        HtmlAttribute width = tdNode.Attributes["width"];
                        if (width == null)
                        {
                            continue;
                        }
                        HtmlNode node;
                        switch (width.Value)
                        {
                        case "40%":
                            node       = tdNode.ChildNodes.FindFirst("a");
                            mylink.Url = node.OuterHtml.Replace("zwxq.asp", "detail.html");
                            break;

                        case "35%":
                            node        = tdNode.ChildNodes.FindFirst("p");
                            mylink.Work = node.InnerHtml.Trim();
                            break;

                        case "10%":
                            node       = tdNode.ChildNodes.FindFirst("p");
                            mylink.Num = node.InnerHtml.Trim();
                            break;

                        case "12%":
                            node        = tdNode.ChildNodes.FindFirst("p");
                            mylink.Time = node.InnerHtml.Trim();
                            break;

                        default:
                            break;
                        }
                    }
                    myLinkList.Add(mylink);
                }
            }
            #endregion

            if (myLinkList.Count > 0)
            {
                var tableJson = new TableJson()
                {
                    myLinkList = myLinkList
                };
                //分页
                int iPageStart = content.IndexOf("<p align='center' vAlign='bottom'>", 0);
                if (iPageStart < 1)
                {
                    return(GetJson(tableJson));
                }
                int iPageEnd = content.IndexOf("转到:", iPageStart);
                if (iPageEnd < 1)
                {
                    return(GetJson(tableJson));
                }
                string       pageContent = content.Substring(iPageStart, iPageEnd + 3 - iPageStart);
                HtmlDocument pageDoc     = new HtmlDocument();
                pageDoc.LoadHtml(pageContent);
                MyPage mypage    = new MyPage();
                var    ANodeList = pageDoc.DocumentNode.SelectNodes("//a");
                if (ANodeList == null)
                {
                    return(GetJson(tableJson));
                }
                foreach (HtmlNode aNode in ANodeList)
                {
                    if (aNode.ChildNodes.FindFirst("font").InnerHtml == "上一页")
                    {
                        mypage.Previous = GetPageParam(aNode.Attributes["href"].Value);
                    }
                    else
                    {
                        mypage.Next = GetPageParam(aNode.Attributes["href"].Value);
                    }
                }
                iPageStart       = pageContent.IndexOf("]&nbsp;&nbsp;", "]&nbsp;&nbsp;".Length);
                iPageEnd         = pageContent.IndexOf("转到:", iPageStart);
                mypage.Desc      = pageContent.Substring(iPageStart, iPageEnd - iPageStart).Replace("]", "");
                tableJson.mypage = mypage;
                return(GetJson(tableJson));
            }
            return("");
        }
Beispiel #2
0
        private string LoadEntities(HttpContext context)
        {
            var    fbsj        = "00";//context.Request["fbsj"];
            var    gzgw        = context.Request["work"];
            var    ssldbm      = context.Request["place"];
            var    page        = context.Request["page"];
            string url         = string.Format(@"http://fjlylm.com/vizpxx.asp?ssldbm={0}&gzgw={1}&fbsj={2}&page={3}", ssldbm, gzgw, fbsj, page);
            string content     = CommonUtility.HttpUtility.Get(url, System.Text.Encoding.Default);
            int    iTableStart = content.IndexOf("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"95%\" class=\"pix9\">", 0);

            if (iTableStart < 1)
            {
                return("");
            }
            int iTableEnd = content.IndexOf("</table>", iTableStart);

            if (iTableEnd < 1)
            {
                return("");
            }
            string strWeb = content.Substring(iTableStart, iTableEnd - iTableStart);

            #region Tr列表

            //生成HtmlDocument
            HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml(strWeb);
            List <MyLink> myLinkList = new List <MyLink>();
            foreach (HtmlNode trNode in doc.DocumentNode.SelectNodes("//tr"))
            {
                if (!trNode.InnerHtml.Contains("font"))
                {
                    var mylink = new MyLink();
                    foreach (HtmlNode tdNode in trNode.ChildNodes)
                    {
                        HtmlAttribute width = tdNode.Attributes["width"];
                        if (width == null)
                        {
                            continue;
                        }
                        HtmlNode node;
                        switch (width.Value)
                        {
                        case "40%":
                            node       = tdNode.ChildNodes.FindFirst("a");
                            mylink.Url = node.OuterHtml.Replace("zwxq.asp", "WorkDetail.html");
                            break;

                        case "35%":
                            node        = tdNode.ChildNodes.FindFirst("p");
                            mylink.Work = node.InnerHtml.Trim();
                            break;

                        case "10%":
                            node       = tdNode.ChildNodes.FindFirst("p");
                            mylink.Num = node.InnerHtml.Trim();
                            break;

                        case "12%":
                            node        = tdNode.ChildNodes.FindFirst("p");
                            mylink.Time = node.InnerHtml.Trim();
                            break;

                        default:
                            break;
                        }
                    }
                    myLinkList.Add(mylink);
                }
            }
            #endregion

            if (myLinkList.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("<table class=\"table table-bordered\"><thead><tr><th>企业名称</th><th>招聘职位</th><th>招聘人数</th><th>登记时间</th></tr></thead><tbody>");

                foreach (var item in myLinkList)
                {
                    sb.AppendFormat(
                        "<tr><th scope=\"row\">{0}</th><td>{1}</td><td>{2}</td><td>{3}</td></tr>",
                        item.Url, item.Work, item.Num, item.Time
                        );
                }
                sb.Append("</tbody></table>");
                //分页

                int iPageStart = content.IndexOf("<p align='center' vAlign='bottom'>", 0);
                if (iPageStart < 1)
                {
                    return(sb.ToString());
                }
                int iPageEnd = content.IndexOf("转到:", iPageStart);
                if (iPageEnd < 1)
                {
                    return(sb.ToString());
                }
                string       pageContent = content.Substring(iPageStart, iPageEnd + 3 - iPageStart);
                HtmlDocument pageDoc     = new HtmlDocument();
                pageDoc.LoadHtml(pageContent);
                MyPage mypage    = new MyPage();
                var    ANodeList = pageDoc.DocumentNode.SelectNodes("//a");
                if (ANodeList == null)
                {
                    return(sb.ToString());
                }
                foreach (HtmlNode aNode in ANodeList)
                {
                    if (aNode.ChildNodes.FindFirst("font").InnerHtml == "上一页")
                    {
                        mypage.Previous = aNode.Attributes["href"].Value;
                    }
                    else
                    {
                        mypage.Next = aNode.Attributes["href"].Value;
                    }
                }
                iPageStart  = pageContent.IndexOf("]&nbsp;&nbsp;", "]&nbsp;&nbsp;".Length);
                iPageEnd    = pageContent.IndexOf("转到:", iPageStart);
                mypage.Desc = pageContent.Substring(iPageStart, iPageEnd - iPageStart);



                sb.AppendFormat(
                    "<nav><ul class=\"pager\"><li><a href='#'onclick=\"queryPage({0})\">上一页</a></li><li><a href='#'onclick=\"queryPage({1})\">下一页</a></li><li>{2}</li><li style=\"display:none;\">转到{3}</li></ul></nav>"
                    , GetPageParam(mypage.Previous), GetPageParam(mypage.Next), mypage.Desc, mypage.SelPage

                    );

                return(sb.ToString());
            }

            return("");
        }