Esempio n. 1
0
        public DownloadThread(string uilpath, string searchtxt, ImageDownload imageDownload)
        {
            if (uilpath != null)
            {
                this.uilpath = uilpath;
                this.referer = searchtxt;
                if (!uilpath.StartsWith("http://", StringComparison.OrdinalIgnoreCase))
                {
                    this.uilpath = Utils.getHost(this.referer) + uilpath;
                }
                this.searchtxt = new Uri(searchtxt).ToString();

                this.imageDownload = imageDownload;
                Thread th = new Thread(new ThreadStart(duwnload));
                th.Start();
            }
            else
            {
                isStoped = true;
            }
        }
Esempio n. 2
0
        private void downloadImage()
        {
            ImageDownload imageDownload = new ImageDownload(urlset, searchtxt);
            imageDownload.startThread();

            dcmtDown.succCount += imageDownload.getSuccessCount();
            isfinish = true;
        }
Esempio n. 3
0
        /// <summary>
        /// 解析document 下载图片
        /// </summary>
        /// <param name="document"></param>
        private void downloadImage(object document)
        {
            //存放解析图片的url路径集合
            HashSet<string> urlset = new HashSet<string>();
            //判断document是否是HtmlDocument对象
            HtmlDocument htducument = document as HtmlDocument;
            if (htducument != null)
            {
                mshtml.IHTMLImgElement imageElement = null;
                try
                {
                    //循环HtmlDocument对象的图片集合数组
                    foreach (HtmlElement image in htducument.Images)
                    {
                        imageElement = (mshtml.IHTMLImgElement)image.DomElement;
                        urlset.Add(imageElement.src);
                    }
                }
                catch (Exception ex) { }
            }
            else
            {
                //如果document不是HtmlDocument对象则以文本方式解析
                urlset = Utils.GetBaiduImageUrlList((string)document);
            }
            //加锁处理allUrlset
            lock (allUrlset)
            {
                urlset.ExceptWith(allUrlset);

                if (urlset.Count != 0)
                {
                    allUrlset.UnionWith(urlset);
                }
            }

            if (urlset.Count != 0)
            {

                ImageDownload imageDownload = new ImageDownload(urlset, searchtxt);
                imageDownload.startThread();

                succCount += imageDownload.getSuccessCount();
            }
        }