Ejemplo n.º 1
0
        public async static Task <List <TagImg> > GetImgFromHtml(string html, bool isHotspot = false)
        {
            Task <List <TagImg> > task = Task.Run(() => {
                HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                doc.LoadHtml(html);
                var imgList = doc.DocumentNode.SelectNodes("//img");
                var w       = 0;
                var h       = 0;
                HtmlAgilityPack.HtmlAttribute tempAttribute = null;

                List <TagImg> list = new List <TagImg>();
                foreach (var item in imgList)
                {
                    TagImg tagImg = new TagImg();
                    tempAttribute = item.Attributes["alt"];
                    tagImg.Alt    = tempAttribute == null ? "":tempAttribute.Value;
                    tempAttribute = item.Attributes["src"];
                    tagImg.Src    = tempAttribute == null ? "" : tempAttribute.Value;

                    tempAttribute = item.Attributes["h"];
                    if (tempAttribute != null)
                    {
                        int.TryParse(tempAttribute.Value, out h);
                    }
                    tempAttribute = item.Attributes["w"];
                    if (tempAttribute != null)
                    {
                        int.TryParse(tempAttribute.Value, out w);
                    }

                    //Search Detail

                    /*
                     * <a class="iusc" style="height:208px;width:333px" m="{&quot;cid&quot;:&quot;1jz2ZvDM&quot;,&quot;purl&quot;:&quot;https://www.927tour.com/News_newsDetail_id_20180408195735146766.html&quot;,&quot;murl&quot;:&quot;http://ynwgm.ynurl.cn/uploadfile/s10/2018/0408/20180408075500850.jpg&quot;,&quot;turl&quot;:&quot;https://tse1-mm.cn.bing.net/th?id=OIP.1jz2ZvDMIyhtns4hK1ay-AHaFJ&amp;pid=15.1&quot;,&quot;md5&quot;:&quot;d63cf666f0cc23286d9ece212b56b2f8&quot;,&quot;shkey&quot;:&quot;&quot;,&quot;t&quot;:&quot;铁路、民航保障游客正常出游&quot;,&quot;mid&quot;:&quot;1034F8C523DE0FCD1B8302CF3C0D52E2DA5E1CD3&quot;,&quot;desc&quot;:&quot;&quot;}" onclick="sj_evt.fire('IFrame.Navigate', this.href); return false;" href="/images/search?view=detailV2&amp;ccid=1jz2ZvDM&amp;id=1034F8C523DE0FCD1B8302CF3C0D52E2DA5E1CD3&amp;thid=OIP.1jz2ZvDMIyhtns4hK1ay-AHaFJ&amp;mediaurl=http%3a%2f%2fynwgm.ynurl.cn%2fuploadfile%2fs10%2f2018%2f0408%2f20180408075500850.jpg&amp;exph=407&amp;expw=585&amp;q=%e6%b8%85%e6%98%8e%e5%81%87%e6%9c%9f%e5%9b%bd%e5%86%85%e6%97%85%e6%b8%b8%e6%8e%a5%e5%be%85%e6%80%bb%e4%ba%ba%e6%95%b01.12%e4%ba%bf&amp;simid=608053044385353052&amp;selectedIndex=32&amp;qft=+filterui%3aphoto-photo" h="ID=images.5601_7,5217.1">
                     *   <div class="img_cont hoff">
                     *       <img class="mimg" style="background-color:#c10a34;color:#c10a34" height="208" width="299" src="https://tse3-mm.cn.bing.net/th?id=OIP.1jz2ZvDMIyhtns4hK1ay-AHaFJ&amp;w=299&amp;h=208&amp;c=7&amp;o=5&amp;pid=1.7" alt="清明假期国内旅游接待总人数1.12亿 的图像结果" />
                     *   </div>
                     * </a>
                     */

                    /*< a class="iusc" style="height:207px;width:276px" m="{&quot;cid&quot;:&quot;Ox2V7JRH&quot;,&quot;purl&quot;:&quot;http://www.wall001.com/nature/under_sky/html/image8.html&quot;,&quot;murl&quot;:&quot;http://wall001.com/nature/under_sky/mxxx01/[wall001.com]_sky_AP23070.jpg&quot;,&quot;turl&quot;:&quot;https://tse2-mm.cn.bing.net/th?id=OIP.Ox2V7JRHXMInhT3_WlPpVgHaFj&amp;pid=15.1&quot;,&quot;md5&quot;:&quot;3b1d95ec94475cc227853dff5a53e956&quot;,&quot;shkey&quot;:&quot;&quot;,&quot;t&quot;:&quot;桌布天堂 --- 晴朗天空 - 藍天白云8&quot;,&quot;mid&quot;:&quot;8A372FC995FECC38853858A07F4171C439B8FA58&quot;,&quot;desc&quot;:&quot;&quot;}" onclick="sj_evt.fire('IFrame.Navigate', this.href); return false;" href="/images/search?view=detailV2&amp;ccid=Ox2V7JRH&amp;id=8A372FC995FECC38853858A07F4171C439B8FA58&amp;thid=OIP.Ox2V7JRHXMInhT3_WlPpVgHaFj&amp;mediaurl=http%3a%2f%2fwall001.com%2fnature%2funder_sky%2fmxxx01%2f%5bwall001.com%5d_sky_AP23070.jpg&amp;exph=768&amp;expw=1024&amp;q=%e5%a4%a9%e7%a9%ba&amp;simid=608010515721882861&amp;selectedIndex=5&amp;qft=+filterui%3aphoto-photo" h="ID=images.5601_7,5055.1"><div class="img_cont hoff"><img class="mimg" style="background-color:#1543b6;color:#1543b6" height="207" width="276" src="https://tse4-mm.cn.bing.net/th?id=OIP.Ox2V7JRHXMInhT3_WlPpVgHaFj&amp;w=276&amp;h=207&amp;c=7&amp;o=5&amp;pid=1.7" alt="天空 的图像结果"></div></a>*/

                    Tuple <bool, string> extractResult = RegexUtil.ExtractBingImage(item.ParentNode.ParentNode.OuterHtml);

                    if (extractResult.Item1 == true || isHotspot == true)
                    {
                        tagImg.DetailUrl = extractResult.Item2;
                        tagImg.Width     = w;
                        tagImg.Height    = h;
                        list.Add(tagImg);
                    }
                }
                return(list);
            });

            return(await task);
        }
Ejemplo n.º 2
0
        public static string GetSrc(this TagImg tag)
        {
            var attr = tag.Attribute("src");

            if (attr == null)
            {
                return(string.Empty);
            }
            return(attr.Value);
        }
Ejemplo n.º 3
0
        public static TagImg Main(string name)
        {
            var size = Urls.GetSize(Urls.MainSys(name));
            var tag  = new TagImg().Src(Urls.Main(name)).Alt("");

            if (size.HasValue)
            {
                tag.Size(size.Value.Width, size.Value.Height);
            }
            return(tag);
        }
Ejemplo n.º 4
0
        private string GetCertView(TagImg certImg, decimal sigId, bool eng = false, bool vendor = false,
                                   bool ru = false)
        {
            var view = H.div[
                certImg.Style("margin:10px 0;"), H.br,
                Url.Graduate().DownloadCert(sigId, eng, vendor, ru, "Скачать").Class("ui-button"),
                ru&& !vendor ? H.div[H.h3["Поделитесь с друзьями!"],
                                     Htmls.AddThis(Html)] : null
                       ];

            return(view.ToString());
        }
Ejemplo n.º 5
0
 public static TagImg lang(this TagImg tag, LangCode value)
 {
     tag.Lang = value; return(tag);
 }
Ejemplo n.º 6
0
 public static TagImg style(this TagImg tag, string value)
 {
     tag.Style = value; return(tag);
 }
Ejemplo n.º 7
0
 public static TagImg name(this TagImg tag, string value)
 {
     tag.Name = value; return(tag);
 }
Ejemplo n.º 8
0
 public static TagImg ismap(this TagImg tag, IsMap value)
 {
     tag.IsMap = value; return(tag);
 }
Ejemplo n.º 9
0
 public static TagImg width(this TagImg tag, Length value)
 {
     tag.Width = value; return(tag);
 }
Ejemplo n.º 10
0
 public static TagImg longdesc(this TagImg tag, string value)
 {
     tag.LongDesc = value; return(tag);
 }
Ejemplo n.º 11
0
 public static TagImg ondblclick(this TagImg tag, string value)
 {
     tag.OnDblClick = value; return(tag);
 }
Ejemplo n.º 12
0
 public static TagImg dir(this TagImg tag, Dir value)
 {
     tag.Dir = value; return(tag);
 }
Ejemplo n.º 13
0
 public static TagImg Size(this TagImg tag, object width, object height)
 {
     return(tag.Width(width).Height(height));
 }
Ejemplo n.º 14
0
        public string WebChecker(string url)
        {
            string   http                 = "http://";
            string   https                = "https://";
            string   lblResult            = String.Empty;
            string   lblStatusDescription = String.Empty;
            string   lblCause             = String.Empty;
            string   innerTextOfTitle     = String.Empty;
            string   contentOfTagMeta     = String.Empty;
            string   tagA                 = String.Empty;
            string   tagImg               = String.Empty;
            string   innerTextOfH1        = String.Empty;
            string   all  = String.Empty;
            DateTime date = DateTime.Now;

            Urls          urllink    = new Urls();
            List <TagA>   tagAList   = new List <TagA>();
            List <TagImg> tagImgList = new List <TagImg>();
            List <TagH1>  tagH1List  = new List <TagH1>();

            try
            {
                //------проверяем есть ли ссылка-------------
                if (string.IsNullOrEmpty(url))
                {
                    MessageBox.Show(@"Вы не вввели ссылку !");
                    return(null);
                }

                //---делаем проверку на наличие протокола "http://" в ссылке запроса
                if (!(url.StartsWith(http) || url.StartsWith(https)))
                {
                    url = url.Insert(0, http);
                }
                //------------------------------------------------------------------

                // Создаём объект запроса
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

                // Получаем ответ с сервера, если запрашиваемый URL не действителен,
                // переходим к блоку catch, иначе идем дальше.
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                if (request.HaveResponse)
                {
                    lblResult            = (response.StatusCode == HttpStatusCode.OK) ? "Сайт доступен" : "Сайт не доступен";
                    lblStatusDescription = response.StatusDescription;
                    lblCause             = ((int)response.StatusCode).ToString();

                    string respStream = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")).ReadToEnd();
                    HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
                    htmlDoc.LoadHtml(respStream);

                    //------ получаем значение тэга Title -------------
                    var nodeTitle = htmlDoc.DocumentNode.SelectNodes("//title");
                    if (nodeTitle != null)
                    {
                        innerTextOfTitle = nodeTitle["title"].InnerText;
                    }
                    //--------------------------------------------------

                    //------ получаем значение атрибута content тэга meta у которого
                    //------ значение атрибута name является description
                    var nodeMeta = htmlDoc.DocumentNode.SelectNodes("//meta");
                    if (nodeMeta != null)
                    {
                        foreach (var tag in nodeMeta)
                        {
                            if (tag.Attributes["name"] != null && tag.Attributes["name"].Value == "description")
                            {
                                contentOfTagMeta = tag.Attributes["content"].Value;
                            }
                        }
                    }
                    //---------------------------------------------------------------

                    //------ получаем значение атрибута href у тэга A -------------
                    var nodesA = htmlDoc.DocumentNode.SelectNodes("//a");
                    if (nodesA != null)
                    {
                        foreach (var tag in nodesA)
                        {
                            if (tag.Attributes["href"] != null)
                            {
                                var link = tag.Attributes["href"].Value;
                                tagA += link + "\n";
                                TagA insTagA = new TagA
                                {
                                    UrlId = urllink.Id,
                                    Href  = link
                                };
                                tagAList.Add(insTagA);
                            }
                        }
                    }
                    //--------------------------------------------------------------

                    //------ получаем значение атрибута src у тэга img -------------
                    var nodesImg = htmlDoc.DocumentNode.SelectNodes("//img");
                    if (nodesImg != null)
                    {
                        foreach (var tag in nodesImg)
                        {
                            if (tag.Attributes["src"] != null)
                            {
                                var src = tag.Attributes["src"].Value;
                                tagImg += src + "\n";
                                TagImg tagImgIns = new TagImg
                                {
                                    UrlId = urllink.Id,
                                    Src   = src
                                };
                                tagImgList.Add(tagImgIns);
                            }
                        }
                    }
                    //---------------------------------------------------------------

                    //------ получаем значение атрибута src у тэга img -------------
                    var nodesH1 = htmlDoc.DocumentNode.SelectNodes("//h1");
                    if (nodesH1 != null)
                    {
                        foreach (var tag in nodesH1)
                        {
                            innerTextOfH1 += tag.InnerText + "\n";
                            int   index    = nodesH1[tag];
                            TagH1 tagH1Ins = new TagH1
                            {
                                UrlId  = urllink.Id,
                                H1Text = tag.InnerText
                            };
                            tagH1List.Add(tagH1Ins);
                        }
                    }
                    //---------------------------------------------------------------

                    StringBuilder newContent = new StringBuilder();
                    newContent.AppendLine("URL: " + url +
                                          "\nДата проверки: " + date +
                                          "\nСтатус: " + lblResult +
                                          "\nОписание статуса: " + lblStatusDescription +
                                          "\nКод статуса: " + lblCause +
                                          "\nTitle: " + innerTextOfTitle +
                                          "\nContent: " + contentOfTagMeta + "\n" +
                                          "\nТэги A: \n" + tagA + "\n" +
                                          "\nТэги Img: \n" + tagImg +
                                          "\nТэги H1: \n" + innerTextOfH1 +
                                          "\n");
                    all = newContent.ToString();

                    urllink.Url               = url;
                    urllink.Title             = innerTextOfTitle;
                    urllink.MetaContent       = contentOfTagMeta;
                    urllink.Status            = lblResult;
                    urllink.StatusDescription = lblStatusDescription;
                    urllink.StatusCode        = lblCause;
                    urllink.DateOfParsing     = date;

                    using (var db = new ParsingResultsEntities())
                    {
                        db.Urls.Add(urllink);
                        db.TagH1.AddRange(tagH1List);
                        db.TagA.AddRange(tagAList);
                        db.TagImg.AddRange(tagImgList);
                        db.SaveChanges();
                    }
                }
                response.Close();
                request.Abort();
                return(all); //возвращаем полученные данные в интерфейс приложения
            }

            catch (WebException ex)
            {
                lblResult            = @"Сайт не доступен";
                lblStatusDescription = ex.Message;

                //---делаем проверку является ли код ошибки HttpStatusCode или WebExceptionStatus
                if (((HttpWebResponse)ex.Response) != null)
                {
                    lblCause = ((int)(((HttpWebResponse)ex.Response).StatusCode)).ToString();
                }
                else
                {
                    lblCause = ((int)(ex.Status)).ToString();
                }
                //-------------------------------------------------------------------------------

                StringBuilder newContent = new StringBuilder();
                newContent.AppendLine("URL: " + url +
                                      "\nДата проверки: " + date +
                                      "\nСтатус: " + lblResult +
                                      "\nОписание статуса: " + lblStatusDescription +
                                      "\nКод статуса: " + lblCause + "\n");
                all = newContent.ToString();

                using (var db = new ParsingResultsEntities())
                {
                    db.Urls.Add(urllink);
                    db.SaveChanges();
                }

                return(all);
            }
        }
Ejemplo n.º 15
0
 public static TagImg src(this TagImg tag, string value)
 {
     tag.Src = value; return(tag);
 }
Ejemplo n.º 16
0
 public static TagImg onmousedown(this TagImg tag, string value)
 {
     tag.OnMouseDown = value; return(tag);
 }
Ejemplo n.º 17
0
 public static TagImg alt(this TagImg tag, string value)
 {
     tag.Alt = value; return(tag);
 }
Ejemplo n.º 18
0
 public static TagImg onmouseup(this TagImg tag, string value)
 {
     tag.OnMouseUp = value; return(tag);
 }
Ejemplo n.º 19
0
 public static TagImg height(this TagImg tag, Length value)
 {
     tag.Height = value; return(tag);
 }
Ejemplo n.º 20
0
 public static TagImg onmousemove(this TagImg tag, string value)
 {
     tag.OnMouseMove = value; return(tag);
 }
Ejemplo n.º 21
0
 public static TagImg usemap(this TagImg tag, string value)
 {
     tag.UseMap = value; return(tag);
 }
Ejemplo n.º 22
0
 public static TagImg onmouseout(this TagImg tag, string value)
 {
     tag.OnMouseOut = value; return(tag);
 }
Ejemplo n.º 23
0
 public static TagImg id(this TagImg tag, string value)
 {
     tag.Id = value; return(tag);
 }
Ejemplo n.º 24
0
 public static TagImg onkeypress(this TagImg tag, string value)
 {
     tag.OnKeyPress = value; return(tag);
 }
Ejemplo n.º 25
0
 public static TagImg @class(this TagImg tag, string value)
 {
     tag.Class = value; return(tag);
 }
Ejemplo n.º 26
0
 public static TagImg onkeydown(this TagImg tag, string value)
 {
     tag.OnKeyDown = value; return(tag);
 }
Ejemplo n.º 27
0
 public static TagImg title(this TagImg tag, string value)
 {
     tag.Title = value; return(tag);
 }
Ejemplo n.º 28
0
 public static TagImg onkeyup(this TagImg tag, string value)
 {
     tag.OnKeyUp = value; return(tag);
 }
Ejemplo n.º 29
0
 public static TagImg xmllang(this TagImg tag, string value)
 {
     tag.XmlLang = value; return(tag);
 }
Ejemplo n.º 30
0
Archivo: Htmls.cs Proyecto: dKluev/Site
 public static TagImg FloatLeft(this TagImg tag)
 {
     return(tag.Class("float_left"));
 }