示例#1
0
        public void exeSpeed(string site)
        {
            try
            {
                var htmlDoc = StringToHtml(site);
                if (htmlDoc.DocumentNode.SelectSingleNode("//article").Id == "article_default")
                {
                    var htmlNodes = htmlDoc.DocumentNode.SelectNodes("//article");
                    if (htmlDoc.DocumentNode.SelectSingleNode("//article/div").GetAttributeValue("class", "erro") == "lista-result-busca")
                    {
                        htmlNodes = htmlDoc.DocumentNode.SelectNodes("//article/div[@class='lista-result-busca']/div");
                    }
                    else
                    {
                        htmlNodes = htmlDoc.DocumentNode.SelectNodes("//article/div[@class='lista-result-busca col-xs-24']/div");
                    }
                    foreach (var node in htmlNodes)
                    {
                        exeSpeed(node.Descendants().ElementAt(1).Descendants().ElementAt(1).GetAttributeValue("href", "erro para pegar o site no artigo padrao"));
                    }
                }
                else if (htmlDoc.DocumentNode.SelectSingleNode("//article").Id == "familia")
                {
                    var htmlNodes = htmlDoc.DocumentNode.SelectNodes("//*[@id='lista-familia']/div");
                    for (int i = 0; i < htmlNodes.Count; i++)
                    {
                        exeSpeed(htmlDoc.DocumentNode.SelectSingleNode("//*[@id='lista-familia']/div[" + (i + 1) + "]/div/div[1]/p/a").GetAttributeValue("href", "erro para pegar o site no artigo familia"));
                    }
                }
                else if (htmlDoc.DocumentNode.SelectSingleNode("//article").Id == "modelo")
                {
                    Verificacao verificacao = new Verificacao();
                    verificacao.Caminho = "//*[@id='mostra-valores']/span[2]/span[2]";


                    byte[] byt = Encoding.Default.GetBytes(htmlDoc.DocumentNode.SelectSingleNode("//*[@id='modelo-vitrine']/div[1]/h2").InnerHtml.ToString());
                    verificacao.Descricao = Encoding.UTF8.GetString(byt);


                    verificacao.Titulo = htmlDoc.DocumentNode.SelectSingleNode("/html/head/meta[6]").GetAttributeValue("content", "erro no modelo");
                    verificacao.Site   = htmlDoc.DocumentNode.SelectSingleNode("//*[@rel='canonical']").GetAttributeValue("href", "erro no modelo").ToString();
                    verificacao.Imagem = htmlDoc.DocumentNode.SelectSingleNode("//*[@id='modelo-vitrine']/div[1]/div/div/span[1]/img").GetAttributeValue("src", "erro na imagem do produto");

                    string marca = htmlDoc.DocumentNode.SelectSingleNode("//*[@id='modelo-vitrine']/div[1]/span").InnerHtml;

                    byte[] bytes = Encoding.Default.GetBytes(htmlDoc.DocumentNode.SelectSingleNode("//*[@id='modelo-vitrine']/div[1]/h1").InnerText.ToString());
                    string nome  = Encoding.UTF8.GetString(bytes);

                    verificacao.ProdutoNome = nome + " - " + marca;

                    this.arrayList.Add(verificacao);
                }
            }
            catch
            {
                Console.WriteLine(site);
            }
        }
示例#2
0
        public void exeCremer(string site)
        {
            try
            {
                var htmlDoc = StringToHtml(site);
                try
                {
                    if (htmlDoc.DocumentNode.SelectSingleNode("//*[@id='col-left']").GetAttributeValue("id", "erro") == "col-left")
                    {
                        if (htmlDoc.DocumentNode.SelectSingleNode("//*[@id='col-left']/nav[1]/ul/li/ul") != null)
                        {
                            var htmlNodes = htmlDoc.DocumentNode.SelectNodes("//*[@id='col-left']/nav[1]/ul/li/ul/li");

                            foreach (var node in htmlNodes)
                            {
                                exeCremer(node.FirstChild.GetAttributeValue("href", "erro para pegar com count na lateral"));
                            }
                        }
                        else
                        {
                            var htmlNodes = htmlDoc.DocumentNode.SelectNodes("//*[@id='divCaixaListagemdepartamentCollection']/div/div/div[2]/ul/li");
                            for (int i = 0; i < htmlNodes.Count; i++)
                            {
                                exeCremer(htmlDoc.DocumentNode.SelectSingleNode("//*[@id='divCaixaListagemdepartamentCollection']/div/div/div[2]/ul/li[" + (i + 1) + "]/div/h3/a").GetAttributeValue("href", "erro para pegar o site no artigo familia"));
                            }
                        }
                    }
                }
                catch
                {
                    Verificacao verificacao = new Verificacao();
                    verificacao.Caminho = "//*[@class='product-price-price']";

                    verificacao.Titulo = htmlDoc.DocumentNode.SelectSingleNode("/html/head/meta[13]").GetAttributeValue("content", "erro no modelo");
                    verificacao.Site   = htmlDoc.DocumentNode.SelectSingleNode("//*[@rel='canonical']").GetAttributeValue("href", "erro no modelo").ToString();
                    verificacao.Imagem = htmlDoc.DocumentNode.SelectSingleNode("//*[@id='imgPrincipalProduto']").GetAttributeValue("src", "erro na imagem do produto");
                    byte[] byt = Encoding.Default.GetBytes(htmlDoc.DocumentNode.SelectSingleNode("//*[@class='product-shortDescription']").InnerHtml.ToString());
                    verificacao.Descricao = Encoding.UTF8.GetString(byt);

                    byte[] bytes = Encoding.Default.GetBytes(htmlDoc.DocumentNode.SelectSingleNode("//*[@class='product-name']/h1").InnerText.ToString());
                    string nome  = Encoding.UTF8.GetString(bytes);

                    verificacao.ProdutoNome = nome;

                    this.arrayList.Add(verificacao);
                }
            }
            catch
            {
                Console.WriteLine(site);
            }
        }