Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 176
  • Last Modified:

accessing the results from a Google search!

I'm in the middle of a year project in university, for which I need to access the results from a Google search and write them to a file so that i can work with the results.

I don't want the results to be returned straight back into the program by Google as I need to gain access to them in order to be able to sort them.

I tried various languages including JavaScript, ASP and HTML with no success, would anyone have any suggestions or links to further information?
1 Solution
I did something like what you describe in Delphi 5.0, though I would think it would be possible in ASP.  However, it is pretty east in Delphi 5.0 with the TWebbrowser component

dorward pointed to the link I was going to - Google offers a SOAP interface, so it's easy to access with .Net or Java.
This kind of thing can be quite easy to do in PHP.

the code would look something like this (untested):

    $search = "tennyson"
    $URL = "http://www.google.com/search?q=".$search."&ie=UTF-8&oe=UTF-8";

     $fileHandle = fopen ($URL, "rb");
     $fileData = fread ($fileHandle, filesize ($URL));
     fclose ($fileHandle);

    // google's matches are of a standard HTML structure. The match titles are prepended by <!--m-->, for example.
    // the result data can therefore be extracted using a global regular expression match.

    if (preg_match_all("'<!--m--><a href.*?</a>'si", $fileData, $matches)) {
        // extract the link text and href
        // output these for use

depending on what you want to do, you can customise the regular expression which does the initial search and chop up the resulting matches to suit your needs.


Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now