Google Search API - Number of Results

前端 未结 1 1932
一整个雨季
一整个雨季 2021-02-04 16:07

Whenever you perform a Google search, it spits out this little snippet of info

\"About 8,110,000 results (0.10 seconds)\"

I\'m using the number of results certa

1条回答
  •  有刺的猬
    2021-02-04 16:59

    Completed using Bing instead of Google and with the following code:

    string baseURL = "http://api.search.live.net/xml.aspx?Appid=&query=%22" + name + "%22&sources=web";
    WebClient c = new WebClient();
    c.DownloadStringAsync(new Uri(baseURL));
    c.DownloadStringCompleted += new DownloadStringCompletedEventHandler(findTotalResults);
    

    and this calls findTotalResults:

    void findTotalResults(object sender, DownloadStringCompletedEventArgs e)
    {
        lock (this)
        {
            string s = e.Result;
            XmlReader reader = XmlReader.Create(new MemoryStream(System.Text.UTF8Encoding.UTF8.GetBytes(s)));
            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (reader.Name.Equals("web:Total"))
                    {
                        gResults = reader.ReadInnerXml();
                    }
    
                }
            }
        }
    }
    

    0 讨论(0)
提交回复
热议问题