wpf c# windows 应用程序中的单选按钮过滤器

radio button filters in wpf c# windows application

我正在开发一个 Link 提取器 C# 应用程序。根据关键字抓取网址。就像当用户使用 txtKeyWords 文本框字段搜索关键字并点击搜索按钮时,他将能够使用开放的 google 搜索运算符 "http://www.google.com/search?num=1000&q=".[= 在任何关键字上获取所需的网址。 20=] 现在我想知道如何添加此代码
http://www.google.com/search?num=50&q=allinurl:site:.edu 以便仅获取 rb1.Checked 下的 edu 链接。就像当用户选中 radio btn1 并在 txtKeyWords 文本框字段中输入所需的关键字时,他就可以获取与查询相关的 .edu Links。我已经做了几次尝试,但无法这样做。这是Search Button

的代码
listBox1.Items.Clear();
            StringBuilder sb = new StringBuilder();
            byte[] ResultsBuffer = new byte[8192];
            string SearchResults = "http://www.google.com/search?num=1000&q=" + txtKeyWords.Text.Trim();
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(SearchResults);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            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();

            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);
                        listBox1.Items.Add(hrefValue.Replace("/url?q=", ""));
                    }
                }
            }

如果您的搜索总是使用 Google,您可能只想使用 URL 本身进行过滤。

因此,您可以将单选按钮文本附加到类似于此的字符串...

string SearchResults = "http://www.google.com/search?num=1000&q=" + txtKeyWords.Text.Trim() + "&as_sitesearch=" + radioButton1.Text.Trim();

这会产生 URL 这样的...

https://www.google.com/search?num=1000&q=cars&as_sitesearch=.edu

然后应根据您的单选框选择(在本例中为 .edu)过滤结果。

现在每个结果应该包含“.edu”

希望对您有所帮助!

忘记提及:如果您需要进一步过滤,请使用 Google 高级搜索,它会构建 URL 供您使用... https://www.google.com/advanced_search