谷歌搜索Windows窗体c# [英] Google search in windows form c#
本文介绍了谷歌搜索Windows窗体c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好。我在c#中有一个简单的问题。我已经使用带有文本框和按钮的Windows窗体构建了一个应用程序。当用户在此文本框中写入单词并按下按钮时,此应用程序将使用google.com搜索Web中的textbox.text,然后将结果保存在文本文件中。我没有使用谷歌API。请帮助我。
Hi. I have a simple question in c#. I have build an application with windows form that has a textbox and a button. When an user writes a word in this textbox and press in button , this application searches textbox.text in the web with google.com and then saves results in a text file. I have no use google api. please help me.
推荐答案
使用Httpwebrequest对象及其选项,我已经解决了这个问题。感谢所有人。
With Httpwebrequest object and its options I`ve solved this problem. thanks of all.
StringBuilder sb = new StringBuilder();
// used on each read operation
byte[] buf = new byte[8192];
string GS = "http://google.com/search?q=";
// prepare the web page we will be asking for
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(GS);
// execute the request
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
// we will read data via the response stream
Stream resStream = response.GetResponseStream();
string tempString = null;
int count = 0;
do
{
// fill the buffer with data
count = resStream.Read(buf, 0, buf.Length);
// make sure we read some data
if (count != 0)
{
// translate from bytes to ASCII text
tempString = Encoding.ASCII.GetString(buf, 0, count);
// continue building the string
sb.Append(tempString);
}
}
while (count > 0);
如果我理解正确,以下链接可以帮助您:
http://kiwigis.blogspot.in/2011/03/google-custom -search-in-c.html [ ^ ]
http://www.eggheadcafe。 com / articles / 20020802.asp [ ^ ]
http:// blog.adamroderick.com/2009/11/google-search-api-with-c-and-json-net/ [ ^ ]
If I understand you correctly, the below links could help you:
http://kiwigis.blogspot.in/2011/03/google-custom-search-in-c.html[^]
http://www.eggheadcafe.com/articles/20020802.asp[^]
http://blog.adamroderick.com/2009/11/google-search-api-with-c-and-json-net/[^]
这篇关于谷歌搜索Windows窗体c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文