Google parser in minutes on Delphi7

    For our task, we need a little knowledge of programming in Delphi, free components from the Embedded Web Browser suite.
    At the very beginning, we need to have Delphi7 installed, and an Internet connection, to check the program.
    To get started, download and install them. The component itself is located here - bsalsa.com/DP/download.php?file=0 .

    Installation steps:
    1. After downloading, unzip to the folder “..: \ Borland \ Delphi7 \ lib”
    3. In Delphi select File -> “Open”
    d1.gif
    Go to the folder (”..: \ Borland \ Delphi5 \ lib \ EmbeddedWB_D2005 \ Source ”).
    5. Select the file “EmbeddedWebBrowser_D7.dpk” and click Open.
    d2.gif
    6. Click compile and install
    7. Everything, the component is installed.
    If everything went well, we proceed to write the program itself, since the preparatory phase is completed.
    Of these components for our task, we need only one - TextIEParser.
    Create a form in Delphi. We put panel on it and edit and speedbutton on it. Statusbar and still memo - setting the Align property to alClient. Do not forget about our IEParser. Change the caption property of the form. We got such a listing of our form: interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, ComCtrls; type TForm1 = class (TForm) StatusBar1: TStatusBar; Panel1: TPanel; Edit1: TEdit; SpeedButton1: TSpeedButton;
    d3.gif


    unit main;










    Memo1: TMemo;
    IEParser1: TIEParser;
    private
    {Private declarations}
    public
    {Public declarations}
    end;
    var
    Form1: TForm1;
    implementation
    {$ R * .dfm}
    end.

    We start methodically adding functionality. Add an OnClick event to our SpeedButton. This is done simply by double-clicking on our button on the form. Such a simple code in this problem will suit us, it gives only the first 100 results. We will consider great opportunities in the following examples, if this will be useful to the people. Now our task is to tear out the code of the links received and put it in Memo. We open our favorite browser with such a request
    procedure TForm1.SpeedButton1Click(Sender: TObject);
    begin
    // задаем как парсить гугл и текст запроса из Edit
    IEParser1.URL:='http://www.google.com/ie?q='+Edit1.Text+'&num=100&hl=en&lr=&newwindow=1&c2coff=1';
    // Запуск парсера
    IEParser1.Go;
    end;



    www.google.com/ie?q=inurl:bbs.cgi&num=100&hl=en&lr=&newwindow=1&c2coff=1
    And run to look at the source of the page. Analyzing the html code of the page, we conclude that all we need is in the tags A. And that those links that do not lead to google, we need.
    We need an event of our IEParser - onAnchor Everything - our just parser is ready!
    procedure TForm1.IEParser1Anchor(Sender: TObject; hRef, Target, Rel, Rev,
    Urn, Methods, Name, Host, HostName, PathName, Port, Protocol, Search,
    Hash, AccessKey, ProtocolLong, MimeType, NameProp: String;
    Element: TElementInfo);
    begin
    if Pos('google', href) = 0 then Memo1.Lines.Add(href);
    StatusBar1.SimpleText:='Find links: '+IntToStr(Memo1.Lines.Count+1);
    end;

    d4.gif

    Also popular now: