Exemplo n.º 1
0
        private keyword GetPosition(string Url, string searchTerm)
        {
            string  html;
            keyword result = new keyword();

            try
            {
                string         raw     = "https://www.google.com.au/search?num=100&q=conveyancing+Software";
                string         search  = string.Format(raw, System.Uri.EscapeDataString(searchTerm));
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(search);
                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
                    {
                        html   = reader.ReadToEnd();
                        result = FindPosition(html, Url);
                    }
                }
            }
            catch (WebException ex)
            {
                using (var sr = new StreamReader(ex.Response.GetResponseStream()))
                    html = sr.ReadToEnd();
            }
            return(result);
        }
Exemplo n.º 2
0
        private keyword FindPosition(string html, string url)
        {
            keyword result = new keyword();
            var     Webget = new HtmlWeb();
            var     page   = Webget.Load("https://www.google.com.au");

            page.LoadHtml(html);

            var list  = page.DocumentNode.SelectNodes("//h3[@class='r']//a");
            int count = list.Count();
            int i     = 0;

            foreach (var obj in list)
            {
                i++;
                if (i > count)
                {
                    break;
                }
                else
                {
                    var urls = obj.SelectSingleNode(".").Attributes["href"].Value;
                    if (urls.Contains(url))
                    {
                        result.Link    = urls;
                        result.Postion = i;
                        return(result);
                    }
                }
            }
            return(null);
        }
Exemplo n.º 3
0
        private void bWorker_DoWork_1(object sender, DoWorkEventArgs e)
        {
            String website = "www.smokeball.com.au";
            String keyword = "Conveyancing Software";
            int    _Count  = 0;

            keyword results = GetPosition(website, keyword);

            if (results.Link != null)
            {
                string link       = results.Link;
                var    linkParser = new Regex(@"\b(?:https?://|www\.)\S+\b?&sa", RegexOptions.Compiled | RegexOptions.IgnoreCase);

                foreach (Match m in linkParser.Matches(link))
                {
                    link = m.Value;
                }
                string pattern     = "&sa";
                string replacement = "";
                Regex  rgx         = new Regex(pattern);
                string new_link    = rgx.Replace(link, replacement);
                if (results.Postion > 0)
                {
                    SEO_DataTable.Rows.Add(website, keyword, results.Postion.ToString(), link);
                    if (SEOData.InvokeRequired)
                    {
                        SEOData.Invoke(new MethodInvoker(delegate { SEOData.DataSource = SEO_DataTable; }));
                    }
                    _Count++;
                }
            }
        }