开发者

How to get google search results in my application?

I have a textbox and a button in my page. On giving something in the textbox and pressing the button it should go to the google server and collect all search result. How to do that?

I can use Google AJAX Search API but can't i do t开发者_高级运维hese things without using the api?


You can establish a TCP connection on port 80, and then manually create the GET request for the google search. You will then need to parse the resulting html to extract the search results.

Have a look at RFC 2616 for more information.

--

Dev, I don't know what programming language you are using, so it's hard for me to give an example, however the concept is easily demonstrated using a telnet client. You can use telnet to connect to google on port 80.

telnet www.google.com 80

From here, you can type your requests. If we do a quick google search in your browser for something and then check the URL, we see something along the lines of

http://www.google.com/search?q=stack+overflow

This gives us the general form of the search request, and from this template, we can construct any search query simply by replacing "stack+overflow" with our desired query. So back in the telnet client, we can type a GET request, after connecting, by typing

GET http://www.google.com/search?q=stack+overflow HTTP/1.0 and then pressing enter twice, to signify the end of the GET request, as double newlines indicate the end of the request. There are a lot of various options for GET requests, which will vary depending on your needs. These options are detailed in the RFC.

After you press enter twice, you should see html. This is the html of the google search results page that would normally be rendered in your web browser.

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜