📜 ⬆️ ⬇️

Google Parser in a few minutes on Delphi7

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

Installation steps:
1. After downloading, unpack to the folder “..: \ Borland \ Delphi7 \ lib”
3. In Delphi, select File -> “Open”
d1.gif
Navigate to the folder ("..: \ Borland \ Delphi5 \ lib \ EmbeddedWB_D2005 \ Source").
5. Select the “EmbeddedWebBrowser_D7.dpk” file and click Open.
d2.gif
6. Click compile and install
7. Everything, the component is installed.
If everything went well, we start writing the program itself, since the preparatory stage is over.
Of these components for our task, we need only one - TextIEParser.
Create a form in Delphi. We place the panel on it and on it edit and speedbutton. Statusbar and another memo - by setting the Align property in alClient. Do not forget about our IEParser.
d3.gif
Change the caption property of the form.
Received such listing of our form:
unit main;
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;
Memo1: TMemo;
IEParser1: TIEParser;
private
{Private declarations}
public
{Public declarations}
end;
var
Form1: TForm1;
implementation
{$ R * .dfm}
end.

Let's start methodically adding functionality. Add an event to the OnClick of our SpeedButton. This is done simply by double clicking on our button on the form.
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;

Such a simple code in this task will suit us, it gives only 100 first results. Great opportunities consider in the following examples, if this will be useful to the people.
Now our task is to tear out the reference code received and put it in the Memo.
Open our favorite browser with this request. www.google.com/ie?q=inurl:bbs.cgi&num=100&hl=en&lr=&newwindow=1&c2coff=1
And run to watch the source of the page. Analyzing the code of the html page we come to the conclusion that all that we need is in the tags A And that those links that do not lead to google, and we need.
We need the event of our IEParser - onAnchor
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
Everything - our parser is just ready!

')

Source: https://habr.com/ru/post/7126/


All Articles