Solved

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

Posted on 2003-11-06
6
214 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
  • 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

830 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