google search api使用c# [英] google search api using c#
本文介绍了google search api使用c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
i想要处理谷歌搜索api以返回网址列表。
喜欢我想搜索这个词:手机
因此它将返回给我一个列表,所有的网址将出现在google.com
只是网址...我没有使用谷歌搜索API之前
所以任何人都可以帮助我吗?
注意:我需要用c#语言。
注2:我需要搜索中出现的所有网址。
hello
i want to deal with google search api to return a list of url.
like i want to search for the word : mobile
so it will return to me a list of all the url would appear in google.com
just the url ... I didn't use google search api before
so any one can help me ?
note : i need it in c# language.
note 2 : i need all the url that appear in search.
推荐答案
搜索示例字符串hello world的URL是:
https://www.google.com.au/search?q=hello %20world [ ^ ]
与HttpWebRequest一起使用并阅读响应。之后,将会有一些工作要做以提取信息。
The URL to search example string "hello world" is :
https://www.google.com.au/search?q=hello%20world[^]
Use this with HttpWebRequest and read the response. After that there will be some work to do to extract the information.
action ..................... >
action.....................
[HttpPost]
public ActionResult GetResult(string term)
{
string apiKey = "Your api key";
string cx = "your search key";
string query = term;
WebClient webClient = new WebClient();
webClient.Headers.Add("user-agent", "Only a test!");
var results = webClient.DownloadString(String.Format("https://www.googleapis.com/customsearch/v1?key={0}&cx={1}&q={2}&alt=json", apiKey, cx, query));
// web.Dispose();
return Json(results);
}
index.chhtml ................... .......
index.chhtml................................
<form id="form1">
<table width="100%">
<tr>
<td colspan="2">
<input id="srchterm" type="text" style="width:500px" />
<button >Search</button>
</td>
</tr>
<tr align="left">
<td style="width:50%">
<div class="demo-container"></div>
</td>
<td align="center" style="width:50% !important;">
<div id="divResultPreview" class="divresultpreview">
</div>
<div id="divLoading" style="margin: 0px; padding: 0px; removed: fixed; removed 0px;<br mode=" hold=" /> top: 0px; width: 100%; height: 100%; background-color: #333333; z-index: 30001;<br mode=">
<p style="removed: absolute; removed 40%; removed 40%; color: White;font-size:medium">
Loading, please wait...<br /><img src="http://localhost:54539/Content/loading-image.gif">
</img></p>
</div>
</td>
</tr>
</table>
</form>
<script type="text/javascript" language="javascript">
function SearchWeb() {
try {
( #divLoading)。show();
var url = ' @ Url.Action (GetResult,Home)';
var term =
("#divLoading").show(); var url = '@Url.Action("GetResult", "Home")'; var term =
这篇关于google search api使用c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文