Yahoo!検索Webサービス ウェブ検索のサンプルコード(VB.NET ) †
Yahoo!検索Webサービスのウェブ検索機能を使って検索を行うサンプルです。なおこのサンプルを実行するには、xsd.exeにより「/c」オプションで作成されたクラスが必要です。このクラスを添付しておきます。
WebSearchResponse.vb 1091件
[詳細]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
| | <%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim requestUrl As String = _
"http://api.search.yahoo.co.jp/WebSearchService/V1/webSearch"
requestUrl += "?appid=XXXXX"
requestUrl += "&query=" + Server.UrlEncode(TextBox1.Text)
If searchType.SelectedValue <> "" AndAlso _
searchType.SelectedValue <> "all" Then
requestUrl += "&type=" + searchType.SelectedValue
End If
If resultsCount.SelectedValue <> "" AndAlso _
resultsCount.SelectedValue <> "10" Then
requestUrl += "&results=" + resultsCount.SelectedValue
End If
If fileFormat.SelectedValue <> "" AndAlso _
fileFormat.SelectedValue <> "any" Then
requestUrl += "&format=" + fileFormat.SelectedValue
End If
If adultOk.Checked Then
requestUrl += "&adult_ok=1"
End If
If similarOk.Checked Then
requestUrl += "&similar_ok=1"
End If
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(searchDomain.Text)
End If
Dim request As System.Net.HttpWebRequest = _
CType(System.Net.WebRequest.Create(requestUrl), _
System.Net.HttpWebRequest)
Dim response As System.Net.HttpWebResponse = Nothing
Dim res As Yahoo.jp.WebSearchResponse.ResultSet
Try
response = CType(request.GetResponse(), _
System.Net.HttpWebResponse)
Dim strm As System.IO.Stream = response.GetResponseStream()
Dim serializer As New System.Xml.Serialization.XmlSerializer( _
GetType(Yahoo.jp.WebSearchResponse.ResultSet))
res = CType(serializer.Deserialize(strm), _
Yahoo.jp.WebSearchResponse.ResultSet)
Catch ex As Exception
Label1.Text = "エラー:" + Server.HtmlEncode(ex.Message)
Return
Finally
If Not (response Is Nothing) Then
response.Close()
End If
End Try
Label1.Text = ""
Label1.Text += "<b>" + Server.HtmlEncode(TextBox1.Text) + _
"</b> の検索結果 約 " + res.totalResultsAvailable + _
"件中 " + res.firstResultPosition + " - " + _
res.totalResultsReturned + " 件目<br />" + vbLf
If Not (res.Result Is Nothing) Then
Label1.Text += "<ul>" + vbLf
Dim item As Yahoo.jp.WebSearchResponse.ResultType
For Each item In res.Result
Label1.Text += "<li><a href=""" + item.ClickUrl + _
""">" + item.Title + "</a>"
If Not (item.Summary Is Nothing) AndAlso _
item.Summary.Length > 0 Then
Label1.Text += "<br />" + item.Summary
End If Label1.Text += "<br /><small>" + item.Url
If Not (item.Cache Is Nothing) Then
Label1.Text += " - " + item.Cache.Size + "byte"
Label1.Text += " - <a href=""" + _
item.Cache.Url + """>キャッシュ</a>"
End If
If Not (item.ModificationDate Is Nothing) AndAlso _
item.ModificationDate.Length > 0 Then
Dim dt As New DateTime(1970, 1, 1)
dt = dt.AddSeconds(Double.Parse(item.ModificationDate))
Label1.Text += " - " + dt.ToShortDateString()
End If
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:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="ウェブ検索" /><br />
キーワードを<asp:CheckBoxList ID="searchType" runat="server"
RepeatDirection="Horizontal"
RepeatLayout="Flow">
<asp:ListItem Selected="True" Value="all">すべて含む</asp:ListItem>
<asp:ListItem Value="any">少なくとも1つ含む</asp:ListItem>
<asp:ListItem Value="phrase">文章として含む</asp:ListItem>
</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>
<asp:ListItem Value="html">HTML (.htm, .html)</asp:ListItem>
<asp:ListItem Value="pdf">Adobe PDF (.pdf)</asp:ListItem>
<asp:ListItem Value="xls">Microsoft Excel (.xls)</asp:ListItem>
<asp:ListItem Value="ppd">Microsoft Power Point (.ppd)</asp:ListItem>
<asp:ListItem Value="msword">Microsoft Word (.doc)</asp:ListItem>
<asp:ListItem Value="rss">RSS/XML (.xml)</asp:ListItem>
<asp:ListItem Value="txt">テキストフォーマット (.txt)</asp:ListItem>
</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" EnableViewState="False">
</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サービス by Yahoo! JAPAN</a>
</span>
<!-- End Yahoo! JAPAN Web Services Attribution Snippet -->
</body>
</html>
|
ページ情報 |
- 作成日 : 2006-09-09 (土) 02:59:13
- 作成者 : DOBON!
- 最終編集日 : 2006-09-09 (土) 03:05:49
- 最終編集者 : DOBON!
|