Ejemplo n.º 1
0
        private void backgroundWorker_genSearchWork(object sender, DoWorkEventArgs e)
        {
            Console.WriteLine("Background worker...");
            if (authorCheckBox.Checked == true)
            {
                prevSelectedIndex = -1;
                // get suggestions
                if (a[0])
                    authSug = CSParser.getAuthSuggestions(searchField.Text);
                else if (a[1])
                {
                    authSug = GSScraper.getAuthSuggestions(searchField.Text);
                }
                else
                    authSug = MSParser.getAuthSuggestions(searchField.Text);

                if (authSug == null || !authSug.isSet())
                {
                    /* Case : No suggestions */
                    if (a[0] == true)
                    {
                        authStats = CSParser.getAuthors(searchField.Text, "", "");
                        authStats.Type = 0;
                    }
                    else if (a[1] == true)
                    {
                        authStats = GSScraper.getAuthors(searchField.Text, "", "", ref gs_nextUrl);
                        if (authStats == null)
                            MessageBox.Show("Oops! You have reached administrative limit for Google Scholar." +
                                "\nIf you are behind a proxy server, please try changing your settings.");
                        else
                            authStats.Type = 1;
                    }
                    else
                    {
                        authStats = MSParser.getAuthors(searchField.Text, "", "");
                        authStats.Type = 2;
                    }
                    suggestions = false;
                }
                else
                {
                    authors = authSug.getSuggestions();
                    auth_url = authSug.getSuggestionsURL();

                    suggestions = true;
                }
            }
            else // journal
            {
                if (a[0])
                {
                    journalStats = CSParser.getJournals(searchField.Text, "", "");
                    journalStats.Type = 0;
                }
                else if (a[1])
                {
                    journalStats = GSScraper.getJournals(searchField.Text, "", "", ref gs_nextUrl);
                    if(journalStats == null)
                       MessageBox.Show("Oops! You have reached administrative limit for Google Scholar." +
                                "\nIf you are behind a proxy server, please try changing your settings.");
                    else
                        journalStats.Type = 1;
                }
                else
                {
                    journalStats = MSParser.getJournals(searchField.Text, "", "");
                    journalStats.Type = 2;
                }
            }
        }
Ejemplo n.º 2
0
        //,ref string next_URL)
        // SUGGESTIONS FROM SEARCH PAGE
        public SG.AuthSuggestion getAuthSuggestions(string authName)
        {
            List<string> names = new List<string>();
            List<string> links = new List<string>();

            /*
            if (latestSearch.Equals("default") || (!latestSearch.Equals(authName)))
            {
                loadHtmlDocument(authName);
            }

            // DID U MEAN TAG
            string xpath = "//*[@class=\"gs_med\"]";
            HtmlNode dymNode = doc.DocumentNode.SelectSingleNode(xpath);

            if (dymNode != null)
            {
                Console.WriteLine("\nDID YOU MEAN TAG ");
                Console.WriteLine(dymNode.InnerText);
            }
            */

            // AUTHOR SUGGESTIONS
            authName = authName.Trim();
            authName = Regex.Replace(authName, @"\s+", "+");
            string url = "http://scholar.google.co.in/citations?view_op=search_authors&mauthors=" + authName + "&hl=en&oi=ao";
            HtmlWeb web = new HtmlWeb();

            try
            {
                doc = web.Load(url);
            }
            catch (Exception e) {
                return null;
            }

            string profiles_url = null;
            string xpath = "//*[@class=\"cit-dark-large-link\"]";
            //string xpath = "//*[@class=\"\"]";
            HtmlNodeCollection profileNode = doc.DocumentNode.SelectNodes(xpath);
            if (profileNode != null)
            {
                foreach (HtmlNode urlNode in profileNode)
                {
                    //HtmlNode urlNode = node.SelectSingleNode(".//a");
                    if (urlNode != null)
                    {
                        profiles_url = urlNode.GetAttributeValue("href", "");
                        names.Add(urlNode.InnerText);
                        if (!profiles_url.Equals(""))
                        {
                            profiles_url = "http://scholar.google.com" + profiles_url;
                            profiles_url = profiles_url.Replace("amp;", "");
                        }
                        links.Add(profiles_url);
                    }

                }

                //NEXT PAGE URL EXTRACTION
                HtmlNode next = doc.DocumentNode.SelectSingleNode("//*[@class=\"g-section cit-dgb\"]//tr/td[2]/a");
                string next_URL;
                if (next != null)
                {
                    next_URL = next.Attributes["href"].Value;
                    next_URL = "http://scholar.google.com" + next_URL;
                    next_URL = next_URL.Replace("amp;", "");
                }
                else next_URL = null;

                //TAKING RESULTS FROM NEXT PAGE
                SG.AuthSuggestion suggestions = new SG.AuthSuggestion(names,links,true);
                getAuthSuggestionsNextPage(next_URL, ref suggestions, ref next_URL);

                return suggestions;
            }
            else return new SG.AuthSuggestion(null, null, false);
        }