我正在使用简单的Google API来显示搜索结果。我想获得鼠标悬停或点击链接的href值。 javascript的味道真的不重要,我只需要获得用户选择的href值就可以了。如何使用jquery获取Google搜索API结果href值
(我需要这个,因为我有一个Web服务,它允许用户保存他们找到感兴趣的链接。)
我在客户端脚本太可怕了,所以我真的可以用一只手。以这里的示例为例,我使用默认的Google AJAX Search API示例。
To visually explain I have posted this image.(不能附加)
我已经使用了链接 - How to get href value using jQuery? - 简单参考无济于事。我相信这是由于显示谷歌搜索结果的方式/页面渲染顺序。
HTML源代码预渲染如下:
<!--
copyright (c) 2009 Google inc.
You are free to copy and use this sample.
License can be found here: code.google.com/apis/ajaxsearch/faq/#license
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google AJAX Search API Sample</title>
<script src="http://www.google.com/jsapi?key=AIzaSyA5m1Nc8ws2BbmPRwKu5gFradvD_hgq6G0" type="text/javascript"></script>
<script type="text/javascript">
/*
* How to do a search that returns the max number of results per page.
*/
google.load('search', '1');
function OnLoad() {
// create a search control
var searchControl = new google.search.SearchControl();
// Set the Search Control to get the most number of results
searchControl.setResultSetSize(google.search.Search.LARGE_RESULTSET);
// Create 2 searchers and add them to the control
searchControl.addSearcher(new google.search.WebSearch());
searchControl.addSearcher(new google.search.BlogSearch());
// Set the options to draw the control in tabbed mode
var drawOptions = new google.search.DrawOptions();
drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED);
// Draw the control onto the page
searchControl.draw(document.getElementById("content"), drawOptions);
// Search!
searchControl.execute("Subaru STI");
}
google.setOnLoadCallback(OnLoad);
</script>
</head>
<body style="font-family: Arial;border: 0 none;">
<div id="content">Loading...</div>
</body>
</html>
The relevent rendered result html source is as follows:
<div class="gs-webResult gs-result">
<div class="gs-title">
<a class="gs-title" href="http://en.wikipedia.org/wiki/Subaru_Impreza_WRX_STI" target="_blank">
<b>Subaru</b> Impreza WRX <b>STI</b> - Wikipedia, the free encyclopedia</a></div>
如果任何人都可以点我在正确的方向,我真的很感激。 感谢百万,戴夫
谢谢。我结束了使用silverlight渲染输出。您的示例适用于使用Jquery的折旧Google api。 – DaveCS 2011-03-22 03:45:35
很确定'live'函数已被弃用。 IIRC,它通过一个额外的参数被集成到'on'中。 – Carcigenicate 2016-02-25 18:49:34