示例#1
0
        static void Main(string[] args)
        {
            WebClient client = new WebClient();

            client.Encoding = System.Text.Encoding.UTF8;
            var html = client.DownloadString("https://blog.csdn.net/czjnoe/article/details/106600070");

            NSoup.Nodes.Document doc = NSoup.NSoupClient.Parse(html);
            //根据标签名获取节点
            NSoup.Select.Elements metaElements = doc.GetElementsByTag("meta");
            foreach (var item in metaElements)
            {
            }
            //根据id获取节点
            NSoup.Nodes.Element headClassElements = doc.GetElementById("head");
            //根据class获取节点
            var headIdElements = doc.GetElementsByClass("fm").ToList();

            foreach (var item in headIdElements)
            {
            }
            //根据属性名称获取节点
            List <Element> attributeNameElements = doc.GetElementsByAttribute("class").ToList();

            //根据属性值获取节点
            List <Element> attributeValueElements = doc.GetElementsByAttributeValue("id", "su").ToList();

            //根据jQuery选择器获取节点
            var selectElments = doc.Select("#head").ToList();
        }
示例#2
0
        private void timAuto_Tick(object sender, EventArgs e)
        {
            String   cPageHtml = geckoWebBrowser1.Text;
            Document doc       = NSoupClient.Parse(cPageHtml);
            Elements rs        = doc.Select(this.txtMatch.Text);

            for (int i = 0; i < rs.Count; i++)
            {
                NSoup.Nodes.Element rowKey = rs[i];
                String cUrl = rowKey.Attr(this.txtAttr.Text);
                log4net.WriteLogFile(cUrl);
            }
        }
示例#3
0
        private void download2()
        {
            // 下载地址
            string url = textBox1.Text;

            string html = getHtml(url);

            NSoup.Nodes.Document d = NSoup.NSoupClient.Parse(html);
            //获取标题
            String title = d.GetElementsByClass("tit").First.GetElementsByTag("h1").Text;

            //如果没有标题就用毫秒数
            title = (title != null && !title.Equals(""))?title:DateTime.Now.ToUniversalTime().Ticks + "";
            NSoup.Nodes.Element   el = d.GetElementById("vlink_1");
            NSoup.Select.Elements es = el.GetElementsByTag("li");

            richTextBox1.Text = "";

            foreach (var e in es)
            {
                string   subHtml = getHtml("http://www.ting56.com" + e.GetElementsByTag("a").Attr("href"));
                Document d1      = NSoup.NSoupClient.Parse(subHtml);

                Match mc = Regex.Match(subHtml, "FonHen_JieMa\\('([0-9,*]*)'\\)");
                //获取加密url
                string   miwen = mc.Groups[1].Value;
                string[] tArr  = Regex.Split(miwen, "\\*", RegexOptions.IgnoreCase);

                int    n = tArr.Length;
                string s = "";
                for (int i = 0; i < n; i++)
                {
                    if (!tArr[i].Equals(""))
                    {
                        s += (char)int.Parse(tArr[i]);
                    }
                }

                //下载地址
                string downUrl = Regex.Split(s, "\\&", RegexOptions.IgnoreCase)[0];
                //文件扩展名
                string downFileExt = Regex.Split(s, "\\&", RegexOptions.IgnoreCase)[2];


                string path = textBox2.Text + "\\" + title + "\\";


                string fileName  = e.Text();
                string localFile = path + fileName + downFileExt;
//              MessageBox.Show(localFile);


                richTextBox1.AppendText("开始下载 " + fileName + "\n\r" + downUrl + "\n\r");

                //用线程执行下载
//				Thread oGetArgThread = new Thread(new ThreadStart(HttpDownload));
//	            oGetArgThread.IsBackground = true;
//	            oGetArgThread.Start();

//				DownFile hd = new DownFile();
//				hd.downUrl=downUrl;
//				hd.localFile=localFile;

//				DownFile df = new DownFile(downUrl,localFile);

//              ThreadPool.QueueUserWorkItem(new WaitCallback(df.HttpDownload));

//				Thread oGetArgThread = new Thread(new ThreadStart(hd.HttpDownload));
//	            oGetArgThread.IsBackground = true;
//	            oGetArgThread.Start();

                HttpDownload(downUrl, localFile);
            }

//			MessageBox.Show(title);
        }