示例#1
0
        public void Post([FromBody] string keyword)
        {
            //New instance
            PBScrape newScrape = new PBScrape();
            //Set Keyword string and scrape keyword
            string postKeyword = keyword;

            newScrape.SetKeyword(postKeyword);
            //Get list of url's off keyword
            List <object> newList = new List <object> {
                newScrape.GetGoogleResults(postKeyword)
            };

            //Step through each URL
            foreach (var url in newList)
            {
                string        instanceUrl    = url.ToString();
                bool          emailMatchBool = false;
                bool          phoneMatchBool = false;
                List <string> parsedDiv      = new List <string> {
                    newScrape.ParseDiv(instanceUrl).ToString()
                };
                newScrape.SetUrl(instanceUrl);
                foreach (var div in parsedDiv)
                {
                    //Email & Phone regex match
                    string emailPattern = _emailRegex;
                    string phonePattern = _phoneRegex;
                    Match  emailMatch   = Regex.Match(div, emailPattern);
                    Match  phoneMatch   = Regex.Match(div, phonePattern);
                    //If email regex match
                    if (emailMatchBool == false)
                    {
                        if (emailMatch.Success)
                        {
                            emailMatchBool = true;
                            newScrape.SetEmail(emailMatch.Value);
                        }
                        else
                        {
                            newScrape.SetEmail("No Match Found");
                        }
                    }
                    //if phone match
                    if (phoneMatchBool == false)
                    {
                        if (phoneMatch.Success)
                        {
                            phoneMatchBool = true;
                            newScrape.SetPhone(phoneMatch.Value);
                        }
                        else
                        {
                            newScrape.SetPhone("No Match Found");
                        }
                    }
                }
                //save instance
                newScrape.Save();
            }
        }