有没有办法从您自己的网站内搜索不同的网站?C#将您的搜索框链接到其他网站的搜索框
例如,当我输入任何搜索查询时,我会在搜索框中创建一个带有搜索框的ASP.net页面,当我输入任何搜索查询时,我将在我的网站中获得结果。
有没有办法从您自己的网站内搜索不同的网站?C#将您的搜索框链接到其他网站的搜索框
例如,当我输入任何搜索查询时,我会在搜索框中创建一个带有搜索框的ASP.net页面,当我输入任何搜索查询时,我将在我的网站中获得结果。
有几种方法去这样做这样的事情:
我假设的目的是为了使其与堆栈溢出工作
1.内置API使用StackOverflows(客户端侧)
你可以找到它的一些细节here。其中包含有关如何执行搜索的详细信息。你可以用像jQuery这样的客户端库来做到这一点。
var URL = "http://api.stackoverflow.com/1.1/";
var _url = URL + 'users?filter=locrizak';
$.ajax({
dataType: 'jsonp',
jsonp: 'jsonp', // <--- add this
url: _url,
success: function(val) {
console.log('success');
},
error: function(val) {
console.log('error');
console.log(arguments);
}
});
2.内置API(服务器端)使用StackOverflows
static void SearchStackOverflow(string y)
{
var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://api.stackoverflow.com/1.1/search?intitle=" + Uri.EscapeDataString(y));
httpWebRequest.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
httpWebRequest.Method = "GET";
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
string responseText;
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
responseText = streamReader.ReadToEnd();
}
var result = (SearchResult)new JavaScriptSerializer().Deserialize(responseText, typeof(SearchResult));
.... do something with result ...
}
class SearchResult
{
public List<Question> questions { get; set; }
}
class Question
{
public string title { get; set; }
public int answer_count { get; set; }
}
3.使用屏幕刮板(不理想当API可用)
这可以用Selenium或Watin等工具完成。 Here is a guide to help you get started with Selenium.
到目前为止的努力? –
我试过使用webclient,但我不确定这是我需要使用的。 – user2061311
您想要搜索哪个网站的搜索结果?应该可以发出一个HttpWebRequest,刮掉响应并显示结果。 如果网站有一个搜索API更容易 – ganeshran