隐藏

采集爱奇艺视频地址

发布:2020/6/9 17:08:57作者:管理员 来源:本站 浏览次数:1273

采集爱奇艺视频地址和时长 描述等内容
public partial class Form1 : Form
    {
        string vidpattern = @"param\['vid'\] = ""([\d\w]+)"";";
        string urlpattern = @"mod-piclist_pic_link"" href=""(http://www.iqiyi.com/(.+).html)";
        string urlpattern1 = @"<a class=""site-piclist_pic_link"" href=""(http://www.iqiyi.com/(.+).html)";
        string timepattern = @"sign-time-right"">([\s\S]*?)</span>";
        string timepattern1 = @"<span class=""mod-listTitle_right"" rseat=""time\d+"">(.+?)</span>";
        string albumIdpattern = @"albumId: ([\d]+),";
        string titlepattern = @"<title>(.+)-爱奇艺</title>";
        string wpattern = @"<link rel=""canonical"" href=""http://www.iqiyi.com/(.+?).html"" />";
 
        string format = @"http://player.video.qiyi.com/{0}/0/0/{1}.swf-albumId={2}-tvId={2}-isPurchase=0-cnId=12";
 
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            List<string> urls = new List<string>();
            List<string> urltime = new List<string>();
            string html = Core.Html.GetHtml(this.textBox1.Text);
            if (!this.checkBox1.Checked)
            {
                urlpattern = urlpattern1;
                timepattern = timepattern1;
            }
            MatchCollection mc = Core.RegHelper.MatchToArray(html,urlpattern ,System.Text.RegularExpressions.RegexOptions.None);
            foreach (Match item in mc)
            {
                if (!urls.Contains(item.Groups[1].Value.Trim()))
                {
                    urls.Add(item.Groups[1].Value.Trim());
                }
            }
            MatchCollection mct = Core.RegHelper.MatchToArray(html, timepattern, System.Text.RegularExpressions.RegexOptions.None);
            foreach (Match item in mct)
            {
                if (!urltime.Contains(item.Groups[1].Value.Trim()))
                {
                    urltime.Add(item.Groups[1].Value.Trim());
                }
            }
            if (urls.Count!=urltime.Count)
            {
                MessageBox.Show("时间和URL居然不对应,是否有错?");
                return;
            }
 
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < urls.Count; i++)
            {
                string h = Core.Html.GetHtml(urls[i]);
                string vid = Core.RegHelper.MatchToString(h,vidpattern,1,0);
                string albumId = Core.RegHelper.MatchToString(h, albumIdpattern, 1);
                string title = Core.RegHelper.MatchToString(h, titlepattern, 1);
                string w = Core.RegHelper.MatchToString(h, wpattern, 1);
 
                string url = string.Format(format, vid, w, albumId);
                sb.AppendLine(title);
                sb.AppendLine(url);
                sb.AppendLine(urltime[i]);
                sb.AppendLine("\r\n\r\n");
            }
            if (sb.ToString() != "")
            {
                Clipboard.SetDataObject(sb.ToString());
                MessageBox.Show("已复制到剪贴板!");
            }
        }
    }