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

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

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
cjclayton
Asked:
cjclayton
  • 3
  • 2
1 Solution
 
huiyueCommented:
I don't know how to settle your problem.
I see your code,but no <title></title> found.
???????
what you want?
0
 
Eddie ShipmanAll-around developerCommented:
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
 
cjclaytonAuthor Commented:
EddieShipman you are on the right track.  Do you have any code samples of this?
0
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!

 
Eddie ShipmanAll-around developerCommented:
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
 
cjclaytonAuthor Commented:
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
 
Eddie ShipmanAll-around developerCommented:
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

Independent Software Vendors: 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!

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