使用javascript从Google搜索中提取任何链接

时间:2011-07-14 08:27:02

标签: javascript jquery mootools

  

可能重复:
  How extract links from iframe using javascript

http://www.google.cl/search?q=food 消息代码:

<html><head>...<img src="GOOGLE LOGO">...
...
<a href="http://www.SEARCH RESULT 1.com"> RESULT FOR FOOD 1</a>
<a href="http://www.SEARCH RESULT 2.net"> RESULT FOR FOOD 2</a>
<a href="http://www.SEARCH RESULT 3.org"> RESULT FOR FOOD 3</a>
<a href="http://www.SEARCH RESULT 4.com"> RESULT FOR FOOD 4</a>
<a href="http://www.SEARCH RESULT 5.us"> RESULT FOR FOOD 5</a>
...
</html>

experimental_test.html 输出

  

谷歌的第三个搜索结果是:


  http://www.SEARCH结果3.org

     

谷歌的第五个搜索结果是:


  http://www.SEARCH结果5.us

experimental_test.html 支持的源代码:

<iframe style="display:none;" src="http://www.google.cl/search?q=food">
<script>
...ge
</script>

换句话说,我想提取具体的链接, 喜欢搜索中的第二个链接。 不想使用PHP

2 个答案:

答案 0 :(得分:0)

您可能无法提取某些内容,因为您无法访问iframe中的文档。

答案 1 :(得分:0)

总之,你不能也不应该。

您不能,因为您不允许使用您的脚本来操纵其他网站的数据。

你不应该因为它违反谷歌的服务条款来搜索搜索结果。您应该使用Custom Search API