Example #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            toolStripStatusLabel1.Text = "inactive";

            comboBoxCity.Enabled = false;
            CheckExtension.getExtensions();
            CheckBannedDomains.getBannedDomains();
            string        fullList  = null;
            List <string> countries = new List <string>();

            using (StreamReader sr = new StreamReader("countries.json"))
            {
                fullList = sr.ReadToEnd();
            }
            countryCities = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, List <string> > >(fullList);
            foreach (string country in countryCities.Keys)
            {
                countries.Add(country);
            }
            countries.Sort();
            foreach (string country in countries)
            {
                comboBoxCountry.Items.Add(country);
            }
            comboBoxCountry.SelectedItem = "United Kingdom";
            radioCountry.Focus();
        }
        public static string getDomain(string query, string city, string address)
        {
            HtmlAgilityPack.HtmlDocument htmlSnippet = new HtmlAgilityPack.HtmlDocument();

            string fullQuery = @"https://www.google.co.uk/#q=" + query + "+hostel+in+" + city;

            fullQuery = fullQuery.Replace("  ", " ");
            fullQuery = fullQuery.Replace(" ", "+");
            //Logger.writeLog(Form1.txtConsole,fullQuery);
            queries.Add(fullQuery);


            StringBuilder sb = new StringBuilder();

            byte[]          ResultsBuffer = new byte[8192];
            string          SearchResults = "http://google.com/search?q=" + query + "+hostel+in+" + city;
            HttpWebRequest  request       = (HttpWebRequest)WebRequest.Create(SearchResults);
            HttpWebResponse response      = (HttpWebResponse)request.GetResponse();

            if (response != null)
            {
            }
            Stream resStream  = response.GetResponseStream();
            string tempString = null;
            int    count      = 0;

            do
            {
                count = resStream.Read(ResultsBuffer, 0, ResultsBuffer.Length);
                if (count != 0)
                {
                    tempString = Encoding.ASCII.GetString(ResultsBuffer, 0, count);
                    sb.Append(tempString);
                }
            }while (count > 0);
            string sbb = sb.ToString();

            List <string> links = new List <string>();

            HtmlAgilityPack.HtmlDocument html = new HtmlAgilityPack.HtmlDocument();
            html.OptionOutputAsXml = true;
            html.LoadHtml(sbb);
            HtmlNode doc = html.DocumentNode;

            foreach (HtmlNode link in doc.SelectNodes("(//a[@href])"))
            {
                //HtmlAttribute att = link.Attributes["href"];
                string hrefValue = link.GetAttributeValue("href", string.Empty);
                if (!hrefValue.ToString().ToUpper().Contains("GOOGLE") && hrefValue.ToString().Contains("/url?q=") && hrefValue.ToString().ToUpper().Contains("HTTP://"))
                {
                    int index = hrefValue.IndexOf("&");
                    if (index > 0)
                    {
                        hrefValue = hrefValue.Substring(0, index);
                        links.Add(hrefValue.Replace("/url?q=", ""));
                    }
                }
            }


            //CHECK LINKS FOR BANNED DOMAINS (HOSTELWORLD ETC)
            bool   notLink   = true;
            string firstLink = null;

            for (int i = 0; notLink; i++)
            {
                if (i < links.Count)
                {
                    if (CheckBannedDomains.check(links[i]))
                    {
                        firstLink = links[i];
                        notLink   = false;
                    }
                }
                else
                {
                    firstLink = "NOPE";
                    notLink   = false;
                }
            }



            //string firstLink = links[0];
            //Logger.writeLog(Form1.txtConsole,firstLink);
            //change this
            return(firstLink);
        }