zoukankan      html  css  js  c++  java
  • 批量下载百度空间所有的 css 皮肤

         正在开发校园博客系统,支持自动换肤,全部自己设计不现实,当然是去扒其他博客系统的了。百度空间的样式漂亮也很多,一个一个人肉下载效率太低,写了个程序下载他所有的css,下了半天下了六七百个。可可~

    代码:

    using System.IO;
    using System.Net;
    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;

    public partial class _Default : System.Web.UI.Page
    {
        private static int TryTimes = 0;
        private readonly static string severPath = HttpContext.Current.Server.MapPath("") + "\\Files\\";
        protected void Page_Load(object sender, EventArgs e)
        {
            //javascript:use('
            for (int k = 0; k < 44; k++)  //总的css有 43页,全部下载下来够狠吧,哈哈!!
            {
                string pagereq = "http://hi.baidu.com/sys/share/index/"+k.ToString();//地址
                string pagestr = GetPost(pagereq);

                string[] temp = pagestr.Split(new string[] { "javascript:use('" }, StringSplitOptions.RemoveEmptyEntries);
                List<string> Ltemp = new List<string>();
                foreach (string s in temp)
                {
                    if (s.IndexOf('\'') == 24)
                        Ltemp.Add(s.Substring(0, 24));
                }
                string[] strcss = Ltemp.ToArray();

                for (int i = 0; i < strcss.Length; i++)
                {

                    string req = "http://www.hi.baidu.com/penjilu/css/item/" + strcss[i] + ".css";//地址

                    TryTimes = 0;
                    string Page = GetPost(req);

                    Response.Write("文件" + strcss[i].ToString() + "______重试" + TryTimes.ToString() + "次<br/>");

                    if (Page != "")
                    {
                        string FileName = severPath + strcss[i] + ".css";

                        Stream w = File.Open(FileName, FileMode.OpenOrCreate);
                        StreamWriter sw = new StreamWriter(w);
                        sw.Write(Page);
                        sw.Close(); sw.Dispose();

                    }
                }

                #region //下载凤凰网的css代码
                //for (int i = 1; i < 16; i++)
                //{
                //    string req = "http://blogfile.ifeng.com/uploadfiles/css/tpl_" + i.ToString() + "/blog_layout_2.css";

                //    TryTimes = 0;
                //    string Page = GetPost(req);
                //    Response.Write("文件"+i.ToString()+"______重试"+TryTimes.ToString()+"次<br/>");
                //    if (Page != "")
                //    {
                //        string FileName = severPath + "blog_layout_" + i.ToString() + ".css";

                //        Stream w = File.Open(FileName, FileMode.OpenOrCreate);
                //        StreamWriter sw = new StreamWriter(w);
                //        sw.Write(Page);
                //        sw.Close(); sw.Dispose();

                //    }
                //}
                #endregion
            }
        }
        private string GetPost( string url)
        {
            if (TryTimes <= 10)
                TryTimes++;
            else
                return "";
            try
            {
                WebRequest web = (HttpWebRequest)WebRequest.Create(url);
                web.Method = "get";
                web.Timeout = 5000;
                WebResponse rep = (HttpWebResponse)web.GetResponse();
                Stream str = rep.GetResponseStream();
                StreamReader r = new StreamReader(str, System.Text.Encoding.GetEncoding("gb2312"));
                string page = r.ReadToEnd();
                r.Close();
                r.Dispose();
                return page;
            }
            catch
            {
                TryTimes++;
                return GetPost(url);
            }
        }
    }

  • 相关阅读:
    GRE协议基础配置
    OSPFv3基础配置
    初级作业2
    缺省静态路由发布进OSPF
    不同进程OSPF路由相互通信
    OSI与TCP/IP
    华为AAA认证详解
    OSPF与静态路由
    [转]那些著名或非著名的iOS面试题(下)
    [转]那些著名或非著名的iOS面试题(中)
  • 原文地址:https://www.cnblogs.com/lulu/p/1147090.html
Copyright © 2011-2022 走看看