Ejemplo n.º 1
0
        public static int GetCoverImageUrl(
            IWin32Window owner,
            string strISSN,
            string strYear,
            string strIssueNo,
            ref CookieContainer cookie,
            out string strImageUrl,
            out string strError)
        {
            strError    = "";
            strImageUrl = "";

            string strUrl = "http://xxdy.qikan.com/MagInfo.aspx?issn=" + strISSN + "&year=" + strYear + "&periodNum=" + strIssueNo;

            /*
             * Connection: Keep-Alive
             * Cookie: xxdy=Default|Default_blue|1674-3121|%e4%b8%ad%e5%b0%8f%e5%ad%a6%e5%be%b7%e8%82%b2|2016|8|xxdy|459|||%e5%b0%8f%e5%ad%a6%e5%be%b7%e8%82%b2%e7%bd%91%e7%ab%99%3ahttp%3a%2f%2fxxdy.qikan.com|2016|9|True|《中小学德育》是由国家教育部委托华南师范大学主办的一本å
             * ¨é¢åæ˜ ä¸­å°å­¦å¾·è‚²å·¥ä½œçš„专业期刊,同时作为中国教育学会中小学德育研究分会会刊。本刊致力于为中小学德育理论研究与实践工作è€
             * 提供最新的德育改革动向、权威的德育政策指引、新锐的德育研究成果、鲜活的德育实践经验,力争成为中小学德育改革的“风向标”,锐意改革的“排头å
             * µâ€ï¼Œå¾·è‚²å·¥ä½œè€
             * 交流经验、探索德育规律的“大舞台”,引领德育行政部门、教研部门和广大德育教师的“参谋部”。%0d%0a编 辑 部:020-85215129  85211209%0d%0a发 行 部:020-85215179  85211443(传真)%0d%0a电子邮箱:[email protected](投稿)%0d%0a          [email protected](订é˜
             * )%0d%0a博客:http://blog.sina.com.cn/s/articlelist_2734759432_0_1.html
             */
            if (cookie == null)
            {
                cookie = new CookieContainer();
            }
            WebClientEx webClient = new WebClientEx(cookie);

#if NO
            {
                byte[] byteArray = x.DownloadData(new Uri("http://xxdy.qikan.com"));
            }

            x = new WebClientEx(cookie);
#endif

            webClient.Headers.Add("Accept", "text/html, application/xhtml+xml, image/jxr, */*");
            webClient.Headers.Add("Accept-Encoding", "gzip, deflate");

            webClient.Headers.Add("Accept-Language", "zh-Hans-CN, zh-Hans; q=0.8, en-US; q=0.5, en; q=0.3");
            //    Host: xxdy.qikan.com
            webClient.Headers.Add("Host", "xxdy.qikan.com");
            // x.BaseAddress = "xxdy.qikan.com";
            webClient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393");
            try
            {
#if NO
                byte[] byteArray = x.DownloadData(new Uri(strUrl));
                Stream stream    = new MemoryStream(byteArray);
                HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
                htmlDoc.OptionFixNestedTags = true;
                htmlDoc.Load(stream, true);


                // ParseErrors is an ArrayList containing any errors from the Load statement
                if (htmlDoc.ParseErrors != null && htmlDoc.ParseErrors.Count() > 0)
                {
                    // Handle any parse errors as required
                    strError = "parse html error: " + htmlDoc.ParseErrors.ToString();
                    return(-1);
                }
#endif
                byte[] byteArray  = webClient.DownloadData(new Uri(strUrl));
                string strContent = Encoding.UTF8.GetString(byteArray);
                // string strContent = x.DownloadString(new Uri(strUrl));
                HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
                htmlDoc.OptionFixNestedTags = true;
                htmlDoc.LoadHtml(strContent);

#if NO
                // ParseErrors is an ArrayList containing any errors from the Load statement
                if (htmlDoc.ParseErrors != null && htmlDoc.ParseErrors.Count() > 0)
                {
                    // Handle any parse errors as required
                    strError = "parse html error: " + htmlDoc.ParseErrors.ToString();
                    return(-1);
                }
#endif

                if (htmlDoc.DocumentNode == null)
                {
                    strError = "htmlDoc.DocumentNode == null";
                    return(-1);
                }

                /*
                 * <div class="left1">
                 * <!--最新封面开始-->
                 *
                 *
                 * <div class="cover1">
                 * <h1>封面</h1>
                 * <div class="cover1_box">
                 *   <a href="../../MagInfo.aspx?issn=1674-3121&year=2013&periodNum=7"><img src="http://img.qikan.com.cn/qkimages/xxdy/xxdy201307-l.jpg" width="190" height="270" border="0" alt="2013年第7期" /></a>
                 *   <span class="f14 fBold"><a href="MagInfo.aspx?issn=1674-3121&year=2013&periodNum=7" title="2013年第7期">2013年第7期</a>
                 *   </span>
                 *
                 * */

#if NO
                HtmlNodeCollection nodes = htmlDoc.DocumentNode.SelectNodes("//img");
                foreach (HtmlNode node in nodes)
                {
                    string src1 = node.GetAttributeValue("src", "");
                    int    i    = 0;
                    i++;
                }
#endif

                HtmlAgilityPack.HtmlNode cover1_box = htmlDoc.DocumentNode.SelectSingleNode("//div[@class='cover1_box']");

                if (cover1_box == null)
                {
                    strError = "cover1_box 没有找到";
                    return(-1);
                }

                HtmlNode img = cover1_box.SelectSingleNode("*/img");
                string   src = img.GetAttributeValue("src", "");
                strImageUrl = src;
                return(1);
            }
            catch (Exception ex)
            {
                strError = "异常: " + ex.Message;
                return(-1);
            }
        }
Ejemplo n.º 2
0
        public static int GetCoverImageUrl(
            IWin32Window owner,
            string strISSN,
            string strYear,
            string strIssueNo,
            ref CookieContainer cookie,
            out string strImageUrl,
            out string strError)
        {
            strError = "";
            strImageUrl = "";

            string strUrl = "http://xxdy.qikan.com/MagInfo.aspx?issn=" + strISSN + "&year=" + strYear + "&periodNum=" + strIssueNo;

            /*
   Connection: Keep-Alive
   Cookie: xxdy=Default|Default_blue|1674-3121|%e4%b8%ad%e5%b0%8f%e5%ad%a6%e5%be%b7%e8%82%b2|2016|8|xxdy|459|||%e5%b0%8f%e5%ad%a6%e5%be%b7%e8%82%b2%e7%bd%91%e7%ab%99%3ahttp%3a%2f%2fxxdy.qikan.com|2016|9|True|《中小学德育》是由国家教育部委托华南师范大学主办的一本å
¨é¢åæ˜ ä¸­å°å­¦å¾·è‚²å·¥ä½œçš„专业期刊,同时作为中国教育学会中小学德育研究分会会刊。本刊致力于为中小学德育理论研究与实践工作è€
提供最新的德育改革动向、权威的德育政策指引、新锐的德育研究成果、鲜活的德育实践经验,力争成为中小学德育改革的“风向标”,锐意改革的“排头å
µâ€ï¼Œå¾·è‚²å·¥ä½œè€
交流经验、探索德育规律的“大舞台”,引领德育行政部门、教研部门和广大德育教师的“参谋部”。%0d%0a编 辑 部:020-85215129  85211209%0d%0a发 行 部:020-85215179  85211443(传真)%0d%0a电子邮箱:[email protected](投稿)%0d%0a          [email protected](订é˜
)%0d%0a博客:http://blog.sina.com.cn/s/articlelist_2734759432_0_1.html
            */
            if (cookie == null)
                cookie = new CookieContainer();
            WebClientEx webClient = new WebClientEx(cookie);

#if NO
            {
                byte[] byteArray = x.DownloadData(new Uri("http://xxdy.qikan.com"));
            }

            x = new WebClientEx(cookie);
#endif

            webClient.Headers.Add("Accept", "text/html, application/xhtml+xml, image/jxr, */*");
            webClient.Headers.Add("Accept-Encoding", "gzip, deflate");

            webClient.Headers.Add("Accept-Language", "zh-Hans-CN, zh-Hans; q=0.8, en-US; q=0.5, en; q=0.3");
            //    Host: xxdy.qikan.com
            webClient.Headers.Add("Host", "xxdy.qikan.com");
            // x.BaseAddress = "xxdy.qikan.com";
            webClient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393");
            try
            {
#if NO
                byte[] byteArray = x.DownloadData(new Uri(strUrl));
                Stream stream = new MemoryStream(byteArray);
                HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
                htmlDoc.OptionFixNestedTags = true;
                htmlDoc.Load(stream, true);


                // ParseErrors is an ArrayList containing any errors from the Load statement
                if (htmlDoc.ParseErrors != null && htmlDoc.ParseErrors.Count() > 0)
                {
                    // Handle any parse errors as required
                    strError = "parse html error: " + htmlDoc.ParseErrors.ToString();
                    return -1;
                }
#endif
                byte[] byteArray = webClient.DownloadData(new Uri(strUrl));
                string strContent = Encoding.UTF8.GetString(byteArray);
                // string strContent = x.DownloadString(new Uri(strUrl));
                HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
                htmlDoc.OptionFixNestedTags = true;
                htmlDoc.LoadHtml(strContent);

#if NO
                // ParseErrors is an ArrayList containing any errors from the Load statement
                if (htmlDoc.ParseErrors != null && htmlDoc.ParseErrors.Count() > 0)
                {
                    // Handle any parse errors as required
                    strError = "parse html error: " + htmlDoc.ParseErrors.ToString();
                    return -1;
                }
#endif

                if (htmlDoc.DocumentNode == null)
                {
                    strError = "htmlDoc.DocumentNode == null";
                    return -1;
                }

                /*
          <div class="left1">
              <!--最新封面开始-->
          

             <div class="cover1">
                 <h1>封面</h1>
                 <div class="cover1_box">
                     <a href="../../MagInfo.aspx?issn=1674-3121&year=2013&periodNum=7"><img src="http://img.qikan.com.cn/qkimages/xxdy/xxdy201307-l.jpg" width="190" height="270" border="0" alt="2013年第7期" /></a>
                     <span class="f14 fBold"><a href="MagInfo.aspx?issn=1674-3121&year=2013&periodNum=7" title="2013年第7期">2013年第7期</a>
                     </span>
                 * 
                 * */

#if NO
                HtmlNodeCollection nodes = htmlDoc.DocumentNode.SelectNodes("//img");
                foreach(HtmlNode node in nodes)
                {
                    string src1 = node.GetAttributeValue("src", "");
                    int i = 0;
                    i++;
                }
#endif

                HtmlAgilityPack.HtmlNode cover1_box = htmlDoc.DocumentNode.SelectSingleNode("//div[@class='cover1_box']");

                if (cover1_box == null)
                {
                    strError = "cover1_box 没有找到";
                    return -1;
                }

                HtmlNode img = cover1_box.SelectSingleNode("*/img");
                string src = img.GetAttributeValue("src", "");
                strImageUrl = src;
                return 1;
            }
            catch (Exception ex)
            {
                strError = "异常: " + ex.Message;
                return -1;
            }
        }