.net页面用谷歌最新API搜索把数据存储到自己的页面中
来源:互联网 发布:淘宝冬之恋羊绒线 编辑:程序博客网 时间:2024/06/05 16:46
首先在网站添加引用
添加GoogleSearchAPI.dll
然后在页面cs文件中添加
using Google.API.Search;
//前台页面代码
<asp:TextBox ID="Txt_Text" runat="server"></asp:TextBox> <asp:Button ID="Btn_Search" runat="server" Text="搜索" OnClick="Btn_Search_Click" /><br /> <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Vertical" OnPageIndexChanging="GridView1_PageIndexChanging"> <RowStyle BackColor="#F7F7DE" /> <Columns> <asp:TemplateField HeaderText="新闻标题" HeaderStyle-HorizontalAlign="Center"> <ItemTemplate> <a href='<%#Eval("URL") %>' target="_blank"> <asp:Label ID="Label1" runat="server" Text='<%# Eval("Title") %>'></asp:Label></a> </ItemTemplate> </asp:TemplateField> <asp:BoundField HeaderText="新闻内容" DataField="Summary" HeaderStyle-HorizontalAlign="Center"> <HeaderStyle VerticalAlign="Middle" /> </asp:BoundField> <asp:TemplateField HeaderText="查看" HeaderStyle-Width="50px" ItemStyle-VerticalAlign="Middle" ItemStyle-HorizontalAlign="Center"> <ItemTemplate> <a href='<%#Eval("URL") %>' target="_blank"> <asp:Label ID="Label2" runat="server" Text="查看"></asp:Label></a> </ItemTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="#CCCC99" /> <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" /> <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" /> <AlternatingRowStyle BackColor="White" /> </asp:GridView>
//核心代码
/// <summary> /// 网络搜索内容结果 /// </summary> private void IntenetSerachResult() { DataTable dtResults = new DataTable(); dtResults.Columns.Add(new DataColumn("Title", typeof(string))); dtResults.Columns.Add(new DataColumn("Summary", typeof(string))); dtResults.Columns.Add(new DataColumn("URL", typeof(string))); foreach (DataRow dr in dt.Rows) { GwebSearchClient s = new GwebSearchClient("这里是自己申请的服务码");//如果不申请每天只能查询10次;申请之后每天能查1000次 IList<IWebResult> r = s.Search(Txt_Text.Text.Trim(), 64);//目前我发现最多能返回64条记录,写100返回也是62条 int estimatedCount = r.Count; foreach (IWebResult item in r) { DataRow dataRow = dtResults.NewRow(); dataRow[0] = item.Title; dataRow[1] = item.Content; dataRow[2] = item.Url; dtResults.Rows.Add(dataRow); } } Label1.Text = "共查询到" + dtResults.Rows.Count.ToString() + "条记录"; GridView2.DataSource = dtResults; GridView2.DataBind(); }
搜索结果
- .net页面用谷歌最新API搜索把数据存储到自己的页面中
- 把百度嵌套到自己的页面
- freemarker怎么把数据显示到页面中?
- 在自己的页面中嵌入百度搜索
- ASP.NET 1.1中页面数据存储方法
- 针对于ASP.NET页面交互时的图形存储到数据库中
- 页面的浏览次数尝试用json数据存储到文件中
- 把页面上DataGrid上的数据读出来并保存到Execl表中,下载到客户端
- asp.net后台将数据显示到页面div中
- 怎么把一个页面的数据传到另一个页面?(.net)(csdn帖子)
- AJax 把拿到的后台数据在页面中渲染
- 把flash加载到jsp页面中
- 将ASP.NET页面内的数据导出到Excel 或 Word中
- 将ASP.NET页面内的数据导出到Excel或Word中
- 将ASP.NET页面内的数据导出到Excel或Word中
- Firebug 如何提供console API到页面的window中
- 第一个redis应用:把一张表的数据保存到内存中,在查询页面调用
- asp.net数据显示到页面
- access函数
- Hibernate hql 中文查询 查不出结果
- DynamicDNSSVR 动态域名更新服务 免费软件
- ubuntu建立vpn服务器 – 陽光小子的日志 – 网易博客
- Linux系统Shell if语句用法小结
- .net页面用谷歌最新API搜索把数据存储到自己的页面中
- JAVA excel 导入
- 优化wordpress,提升访问速度
- 视频开发选择
- ecshop二次开发必看的教程=====smarty --foreach详解(不错不错)
- lr_eval_string()
- There’s more to write a web application
- Yii高性能php框架介绍 – php开源项目交流
- Android入门:Pull解析XML