DoboWiki
Top
> 自由区/Webサービス紹介/Yahoo!検索Webサービス/ウェブ検索/コード/VB.NET をテンプレートにして作成
自由区/Webサービス紹介/Yahoo!検索Webサービス/ウェブ検索/コード/VB.NET をテンプレートにして作成
開始行:
*Yahoo!検索Webサービス ウェブ検索のサンプルコード(VB.NET...
Yahoo!検索Webサービスのウェブ検索機能を使って検索を行うサ...
#attach(noform)
#code(vbnet){{
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional...
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Button1_Click(ByVal sender As Object, B...
'URLを構築する
Dim requestUrl As String = _
"http://api.search.yahoo.co.jp/WebSearchServi...
'アプリケーションIDを指定(必ず指定すること)
requestUrl += "?appid=XXXXX"
'検索クエリー。UTF-8エンコードする。
requestUrl += "&query=" + Server.UrlEncode(TextBo...
'検索の種類
If searchType.SelectedValue <> "" AndAlso _
searchType.SelectedValue <> "all" Then
requestUrl += "&type=" + searchType.SelectedV...
End If
'表示件数
If resultsCount.SelectedValue <> "" AndAlso _
resultsCount.SelectedValue <> "10" Then
requestUrl += "&results=" + resultsCount.Sele...
End If
'開始位置
'requestUrl += "&start=" + "1";
'検索するファイルの種類
If fileFormat.SelectedValue <> "" AndAlso _
fileFormat.SelectedValue <> "any" Then
requestUrl += "&format=" + fileFormat.Selecte...
End If
'アダルトコンテンツを含める
If adultOk.Checked Then
requestUrl += "&adult_ok=1"
End If
'同じコンテンツを別の検索結果として表示する
If similarOk.Checked Then
requestUrl += "&similar_ok=1"
End If
'日本語のページのみ検索する(デフォルトでjaとある...
If englishOnly.Checked Then
requestUrl += "&language=ja"
End If
'日本のサイトのみ検索する
If japanOnly.Checked Then
requestUrl += "&country=jp"
End If
'検索するドメインを指定する
If searchDomain.Text <> "" Then
requestUrl += "&site=" + Server.UrlEncode(sea...
End If
'HttpWebRequestの作成
Dim request As System.Net.HttpWebRequest = _
CType(System.Net.WebRequest.Create(requestUrl...
System.Net.HttpWebRequest)
Dim response As System.Net.HttpWebResponse = Noth...
Dim res As Yahoo.jp.WebSearchResponse.ResultSet
Try
'レスポンスの取得
response = CType(request.GetResponse(), _
System.Net.HttpWebResponse)
Dim strm As System.IO.Stream = response.GetRe...
'サーバーから返されたXMLデータを解析
Dim serializer As New System.Xml.Serializatio...
GetType(Yahoo.jp.WebSearchResponse.Result...
res = CType(serializer.Deserialize(strm), _
Yahoo.jp.WebSearchResponse.ResultSet)
Catch ex As Exception
Label1.Text = "エラー:" + Server.HtmlEncode(...
Return
Finally
If Not (response Is Nothing) Then
response.Close()
End If
End Try
'結果を表示
Label1.Text = ""
Label1.Text += "<b>" + Server.HtmlEncode(TextBox1...
"</b> の検索結果 約 " + res.totalResultsAvail...
"件中 " + res.firstResultPosition + " - " + _
res.totalResultsReturned + " 件目<br />" + vbLf
'検索されたページを列挙
If Not (res.Result Is Nothing) Then
Label1.Text += "<ul>" + vbLf
Dim item As Yahoo.jp.WebSearchResponse.Result...
For Each item In res.Result
'リンク
Label1.Text += "<li><a href=""" + item.Cl...
""">" + item.Title + "</a>"
'要約
If Not (item.Summary Is Nothing) AndAlso _
item.Summary.Length > 0 Then
Label1.Text += "<br />" + item.Summary
End If 'URL
Label1.Text += "<br /><small>" + item.Url
'キャッシュ情報
If Not (item.Cache Is Nothing) Then
Label1.Text += " - " + item.Cache.Siz...
Label1.Text += " - <a href=""" + _
item.Cache.Url + """>キャッシュ</...
End If
'更新日
If Not (item.ModificationDate Is Nothing)...
item.ModificationDate.Length > 0 Then
'UNIXタイムスタンプをDateTimeに変換
Dim dt As New DateTime(1970, 1, 1)
dt = dt.AddSeconds(Double.Parse(item....
Label1.Text += " - " + dt.ToShortDate...
End If
'MIMEタイプ
If Not (item.MimeType Is Nothing) AndAlso _
item.MimeType.Length > 0 Then
Label1.Text += " - " + item.MimeType
End If
Label1.Text += "</small>" + ControlChars.Lf
Next item
Label1.Text += "</ul>" + ControlChars.Lf
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Yahoo!ウェブ検索Webサービスのサンプル</title>
</head>
<body>
<form id="form1" runat="server">
<div>
キーワード :
<asp:TextBox ID="TextBox1" runat="server"></asp:T...
<asp:Button ID="Button1" runat="server" OnClick="...
Text="ウェブ検索" /><br />
キーワードを<asp:CheckBoxList ID="searchType" run...
RepeatDirection="Horizontal"
RepeatLayout="Flow">
<asp:ListItem Selected="True" Value="all">す...
<asp:ListItem Value="any">少なくとも1つ含む</...
<asp:ListItem Value="phrase">文章として含む</...
</asp:CheckBoxList><br />
表示件数 :
<asp:DropDownList ID="resultsCount" runat="server">
<asp:ListItem Value="10">10件</asp:ListItem>
<asp:ListItem Value="25">25件</asp:ListItem>
<asp:ListItem Value="50">50件</asp:ListItem>
</asp:DropDownList><br />
ファイル形式 :
<asp:DropDownList ID="fileFormat" runat="server">
<asp:ListItem Value="any">すべてのファイル形...
<asp:ListItem Value="html">HTML (.htm, .html)...
<asp:ListItem Value="pdf">Adobe PDF (.pdf)</a...
<asp:ListItem Value="xls">Microsoft Excel (.x...
<asp:ListItem Value="ppd">Microsoft Power Poi...
<asp:ListItem Value="msword">Microsoft Word (...
<asp:ListItem Value="rss">RSS/XML (.xml)</asp...
<asp:ListItem Value="txt">テキストフォーマッ...
</asp:DropDownList><br />
<asp:CheckBox ID="adultOk" runat="server"
Text="アダルトコンテンツを含める" /><br />
<asp:CheckBox ID="similarOk" runat="server"
Text="類似の結果を含める" /><br />
<asp:CheckBox ID="englishOnly" runat="server"
Text="日本語のページのみ" /><br />
<asp:CheckBox ID="japanOnly" runat="server"
Text="日本にあるウェブサイトのみ" /><br />
ドメイン :
<asp:TextBox ID="searchDomain" runat="server">
</asp:TextBox><br />
<br />
<asp:Label ID="Label1" runat="server" EnableViewS...
</asp:Label>
</div>
</form>
<!-- Begin Yahoo! JAPAN Web Services Attribution Snippet ...
<span style="margin:15px 15px 15px 15px">
<a href="http://developer.yahoo.co.jp/about">Webサービス ...
</span>
<!-- End Yahoo! JAPAN Web Services Attribution Snippet -->
</body>
</html>
}}
//これより下は編集しないでください
#pageinfo(,2006-09-09 (土) 02:59:13,DOBON!,2006-09-09 (土...
終了行:
*Yahoo!検索Webサービス ウェブ検索のサンプルコード(VB.NET...
Yahoo!検索Webサービスのウェブ検索機能を使って検索を行うサ...
#attach(noform)
#code(vbnet){{
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional...
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Button1_Click(ByVal sender As Object, B...
'URLを構築する
Dim requestUrl As String = _
"http://api.search.yahoo.co.jp/WebSearchServi...
'アプリケーションIDを指定(必ず指定すること)
requestUrl += "?appid=XXXXX"
'検索クエリー。UTF-8エンコードする。
requestUrl += "&query=" + Server.UrlEncode(TextBo...
'検索の種類
If searchType.SelectedValue <> "" AndAlso _
searchType.SelectedValue <> "all" Then
requestUrl += "&type=" + searchType.SelectedV...
End If
'表示件数
If resultsCount.SelectedValue <> "" AndAlso _
resultsCount.SelectedValue <> "10" Then
requestUrl += "&results=" + resultsCount.Sele...
End If
'開始位置
'requestUrl += "&start=" + "1";
'検索するファイルの種類
If fileFormat.SelectedValue <> "" AndAlso _
fileFormat.SelectedValue <> "any" Then
requestUrl += "&format=" + fileFormat.Selecte...
End If
'アダルトコンテンツを含める
If adultOk.Checked Then
requestUrl += "&adult_ok=1"
End If
'同じコンテンツを別の検索結果として表示する
If similarOk.Checked Then
requestUrl += "&similar_ok=1"
End If
'日本語のページのみ検索する(デフォルトでjaとある...
If englishOnly.Checked Then
requestUrl += "&language=ja"
End If
'日本のサイトのみ検索する
If japanOnly.Checked Then
requestUrl += "&country=jp"
End If
'検索するドメインを指定する
If searchDomain.Text <> "" Then
requestUrl += "&site=" + Server.UrlEncode(sea...
End If
'HttpWebRequestの作成
Dim request As System.Net.HttpWebRequest = _
CType(System.Net.WebRequest.Create(requestUrl...
System.Net.HttpWebRequest)
Dim response As System.Net.HttpWebResponse = Noth...
Dim res As Yahoo.jp.WebSearchResponse.ResultSet
Try
'レスポンスの取得
response = CType(request.GetResponse(), _
System.Net.HttpWebResponse)
Dim strm As System.IO.Stream = response.GetRe...
'サーバーから返されたXMLデータを解析
Dim serializer As New System.Xml.Serializatio...
GetType(Yahoo.jp.WebSearchResponse.Result...
res = CType(serializer.Deserialize(strm), _
Yahoo.jp.WebSearchResponse.ResultSet)
Catch ex As Exception
Label1.Text = "エラー:" + Server.HtmlEncode(...
Return
Finally
If Not (response Is Nothing) Then
response.Close()
End If
End Try
'結果を表示
Label1.Text = ""
Label1.Text += "<b>" + Server.HtmlEncode(TextBox1...
"</b> の検索結果 約 " + res.totalResultsAvail...
"件中 " + res.firstResultPosition + " - " + _
res.totalResultsReturned + " 件目<br />" + vbLf
'検索されたページを列挙
If Not (res.Result Is Nothing) Then
Label1.Text += "<ul>" + vbLf
Dim item As Yahoo.jp.WebSearchResponse.Result...
For Each item In res.Result
'リンク
Label1.Text += "<li><a href=""" + item.Cl...
""">" + item.Title + "</a>"
'要約
If Not (item.Summary Is Nothing) AndAlso _
item.Summary.Length > 0 Then
Label1.Text += "<br />" + item.Summary
End If 'URL
Label1.Text += "<br /><small>" + item.Url
'キャッシュ情報
If Not (item.Cache Is Nothing) Then
Label1.Text += " - " + item.Cache.Siz...
Label1.Text += " - <a href=""" + _
item.Cache.Url + """>キャッシュ</...
End If
'更新日
If Not (item.ModificationDate Is Nothing)...
item.ModificationDate.Length > 0 Then
'UNIXタイムスタンプをDateTimeに変換
Dim dt As New DateTime(1970, 1, 1)
dt = dt.AddSeconds(Double.Parse(item....
Label1.Text += " - " + dt.ToShortDate...
End If
'MIMEタイプ
If Not (item.MimeType Is Nothing) AndAlso _
item.MimeType.Length > 0 Then
Label1.Text += " - " + item.MimeType
End If
Label1.Text += "</small>" + ControlChars.Lf
Next item
Label1.Text += "</ul>" + ControlChars.Lf
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Yahoo!ウェブ検索Webサービスのサンプル</title>
</head>
<body>
<form id="form1" runat="server">
<div>
キーワード :
<asp:TextBox ID="TextBox1" runat="server"></asp:T...
<asp:Button ID="Button1" runat="server" OnClick="...
Text="ウェブ検索" /><br />
キーワードを<asp:CheckBoxList ID="searchType" run...
RepeatDirection="Horizontal"
RepeatLayout="Flow">
<asp:ListItem Selected="True" Value="all">す...
<asp:ListItem Value="any">少なくとも1つ含む</...
<asp:ListItem Value="phrase">文章として含む</...
</asp:CheckBoxList><br />
表示件数 :
<asp:DropDownList ID="resultsCount" runat="server">
<asp:ListItem Value="10">10件</asp:ListItem>
<asp:ListItem Value="25">25件</asp:ListItem>
<asp:ListItem Value="50">50件</asp:ListItem>
</asp:DropDownList><br />
ファイル形式 :
<asp:DropDownList ID="fileFormat" runat="server">
<asp:ListItem Value="any">すべてのファイル形...
<asp:ListItem Value="html">HTML (.htm, .html)...
<asp:ListItem Value="pdf">Adobe PDF (.pdf)</a...
<asp:ListItem Value="xls">Microsoft Excel (.x...
<asp:ListItem Value="ppd">Microsoft Power Poi...
<asp:ListItem Value="msword">Microsoft Word (...
<asp:ListItem Value="rss">RSS/XML (.xml)</asp...
<asp:ListItem Value="txt">テキストフォーマッ...
</asp:DropDownList><br />
<asp:CheckBox ID="adultOk" runat="server"
Text="アダルトコンテンツを含める" /><br />
<asp:CheckBox ID="similarOk" runat="server"
Text="類似の結果を含める" /><br />
<asp:CheckBox ID="englishOnly" runat="server"
Text="日本語のページのみ" /><br />
<asp:CheckBox ID="japanOnly" runat="server"
Text="日本にあるウェブサイトのみ" /><br />
ドメイン :
<asp:TextBox ID="searchDomain" runat="server">
</asp:TextBox><br />
<br />
<asp:Label ID="Label1" runat="server" EnableViewS...
</asp:Label>
</div>
</form>
<!-- Begin Yahoo! JAPAN Web Services Attribution Snippet ...
<span style="margin:15px 15px 15px 15px">
<a href="http://developer.yahoo.co.jp/about">Webサービス ...
</span>
<!-- End Yahoo! JAPAN Web Services Attribution Snippet -->
</body>
</html>
}}
//これより下は編集しないでください
#pageinfo(,2006-09-09 (土) 02:59:13,DOBON!,2006-09-09 (土...
ページ名:
▲
▼
[
トップ
] [
新規
|
子ページ作成
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
]