Extract any links from the Google search with javascript [duplicate]
Possible Duplicate:
How extract links from iframe using javascript
http://www.google.cl/search?q=food
SOURCE CODE:
<html><head>...<img src="GOOGLE LOGO">...
...
<a href="http://www.SE开发者_如何学GoARCH 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
OUTPUT:
the third search result from google is:
http://www.SEARCH RESULT 3.orgthe fifth search result from google is:
http://www.SEARCH RESULT 5.us
experimental_test.html
SUPPOSED source code:
<iframe style="display:none;" src="http://www.google.cl/search?q=food">
<script>
...ge
</script>
In other words, I want to extract the specific links, like the second link in the search. Without wanting to use PHP
You may not extract something, because you don't have any access to the document inside the iframe.
In short you can't and you shouldn't.
You can't because you're not allowed to use your script to manipulate data from other website.
You shouldn't because it's against Google's TOS to scrape the search results. You should use the Custom Search API.
精彩评论