Solved

How to view title,desc,keywords from a website url passed via content field in CGI app

Posted on 2003-11-06
6
215 Views
Last Modified: 2010-04-05
How do I extract/view the title, description, keywords from a website url passed via content field in CGI app.

Please alter the following code to work:

Var
  sl : TStringList;
begin
  sl := TStringList.Create;
  try
    // Look up website URL past from content field.
    // Use: Request.ContentFields.Values['WEBSITE_URL']

    // Display website URL
    sl.Add(Format('Website: %s<br><br>',[Request.ContentFields.Values['WEBSITE_URL']]));

    // Extract website header title.
    sl.Add(Format('title: %s<br><br>',['????']));

    // Extract website header description
    sl.Add(Format('description: %s<br><br>',['????']));

    // Extract website header keywords.
    sl.Add(Format('keywords: %s<br><br>',['????']));

    // Past back output.
    Response.Content := sl.Text;

  finally
    sl.Free;
  end;
end;

Thankss
cjclayton
0
Comment
Question by:cjclayton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 

Expert Comment

by:huiyue
ID: 9699719
I don't know how to settle your problem.
I see your code,but no <title></title> found.
???????
what you want?
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 9702474
You will have to "download" the URL's HTML into your app using something like
httpget or Indy's idHTTP and then parse the tags, <title> and <meta>.

0
 

Author Comment

by:cjclayton
ID: 9704374
EddieShipman you are on the right track.  Do you have any code samples of this?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 26

Accepted Solution

by:
EddieShipman earned 125 total points
ID: 9725493
OK, try this out, Not sure if you can get to it if you are not registered with that group, and no, I did not find all
of the code there, I only enhanced some code I already had to get the Meta tags.
Must have mshtml (d6 and up otherwise mshtml2_tlb imported) in your uses...

procedure TForm1.ParseURL(AURL: String);
Var
  IDoc:IHTMLDocument2;
  Strm:TSTringStream;
  v:Variant;
  vTitle  : string;
  i       : Integer;
  vMeta   : IHTMLMetaElement;
  vAll    : IHTMLElementCollection;
  vElement: IHTMLElement;
begin
  Memo1.Clear;
  Strm:=TSTringStream.create('');
  Idhttp1.Get(AURL,strm);
  Idoc:=CreateComObject(Class_HTMLDocument) as IHTMLDocument2;
  IDoc.designMode:='on';
  while IDoc.readyState<>'complete' do
    Application.ProcessMessages;
  v:=VarArrayCreate([0,0],VarVariant);
  v[0]:= Strm.datastring;
  IDoc.write(PSafeArray(System.TVarData(v).VArray));
  IDoc.designMode:='off';
  while IDoc.readyState<>'complete' do
    Application.ProcessMessages;

  vTitle := iDoc.Title;
  Memo1.Lines.Add(vTitle);
  Memo1.Lines.Add('');
  vAll := iDoc.all;
  for i:=0 to vAll.Length-1 do
  begin
    vElement:= vAll.item(i, varEmpty) as IHTMLElement;

    if (vElement <> nil) and (vElement.Tagname='META') then
    begin
      vMeta := vAll.item(i, varEmpty) as IHTMLMetaElement;
      if (vMeta.httpequiv='Keywords') or (vMeta.httpequiv='') then
      begin
        Memo1.Lines.Add(vMeta.content);
      end;
    end;
  end;
  IDoc := nil;
  Strm.Free;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ParseURL('http://groups.yahoo.com/group/delphi-webbrowser/messagesearch?query=meta%20keywords');
end;

0
 

Author Comment

by:cjclayton
ID: 9726085
I'm only using Delphi 5.  How do I get mshtml2_tlb imported working.  Where do I download it from and how do I install it?
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 9726346
From the main menu select Project->Import Type Library.
When the dialog comes up go down in the list until you find
"Microsoft HTML Object Library", then click Install and install
it into whatever package you want.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month4 days, 21 hours left to enroll

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question