Parse simple HTML Tables – embarcadero.delphi.xml

like this:

<TABLE cellpadding=3 cellspacing=0 width="100%"><TR><TD align="right" 
class="cartbasic"><P class="smallfade">First name</P></TD><TD 
class="cartbasic"><P>Peter</P></TD></TR>
<TR><TD align="right" class="cartbasic"><P class="smallfade">Last 
name</P></TD><TD class="cartbasic"><P>Smith</P></TD></TR>
<TR><TD align="right" class="cartbasic"><P 
class="smallfade">Address</P></TD><TD class="cartbasic"><P>Home street 
46</P></TD></TR>
<TR><TD align="right" class="cartbasic"><P 
class="smallfade">ZIP</P></TD><TD class="cartbasic"><P>87300</P></TD></TR>
</TABLE>

and the information taken out from there looks like this:

  First name  Peter
  Last name   Smith
  Address     Home street 46
  ZIP         87300

So, are there any obvious, simple HTML parse algorithms available for 
Delphi that could do this?

There are a lot of HTML-parsers in general. I have studied for instance 
the parsing code from this free Browser component:
http://pbear.com/htmlviewers.html.
After two days of studying, I have to admit that I can't get a grab of 
this parser. I do not get how to use this nice HTML-tool to parse data 
from my Html-tables. The code is far too advanced and complicated for my 
tiny need.

I also found that TWebBrowser component would be able to parse those 
HTML-tables, like this:

procedure TForm1.Button1Click(Sender: TObject);
var
  i, j: Integer;
  ovTable: OleVariant;
begin
  ovTable := WebBrowser1.OleObject.Document.all.tags('TABLE').item(0);
  for i := 0 to (ovTable.Rows.Length - 1) do
  begin
    for j := 0 to (ovTable.Rows.Item(i).Cells.Length - 1) do
    begin
      StringGrid1.Cells[j+1, i+1] :=
        ovTable.Rows.Item(i).Cells.Item(j).InnerText;
    end;
  end;

This way the data goes nicely go TStringGrid.

 

Finding and replacing a string within a text file

Finding and replacing a string within a text file


Try loading the html file into a RichEdit 
The following example shows how to search and replace in the RichEdit

Var 
  TheFile : String; 
  SearchStringPos : Integer; 
  YourSearchString : ShortString; 
  YourReplaceString : ShortString; 
begin 
  RichEdit1.PlainText:=true; 
  RichEdit1.Lines.LoadFromFile(‘YourFile.html’); 
  YourSearchString := ‘<BR>’; 
  YourReplaceString := ‘<HR>’; 
  TheFile:=RichEdit1.Text; 
  SearchStringPos:=Pos(YourSearchString,TheFile); 
  While SearchStringPos > 0 do 
  begin 
    RichEdit1.SelStart:=SearchStringPos-1; 
    RichEdit1.SelLength:=length(YourSearchString); 
    RichEdit1.SelText:=YourReplaceString; 
    TheFile:=RichEdit1.Text; 
    SearchStringPos:=Pos(YourSearchString,TheFile) 
  end; 
  RichEdit1.Lines.SaveToFile(‘YourFile.html’); 
end;

[Delphi] Capturing a Screen Shot of Web page using TWebBrowser

[Delphi] Capturing a Screen Shot of Web page using TWebBrowser

TWebBrowser is not only for Webpage visiting, full page captures and save as Jpg is available.

The program shows below is TWebbrowser to visit a website and capture the screen to save to JPG:

uses ActiveX;

procedure WebBrowserScreenShot(const wb: TWebBrowser; const fileName: TFileName) ;
var
  viewObject : IViewObject;
  r : TRect;
  bitmap : TBitmap;
begin
  if wb.Document <> nil then
  begin
    wb.Document.QueryInterface(IViewObject, viewObject) ;
    if Assigned(viewObject) then
    try
      bitmap := TBitmap.Create;
      try
        r := Rect(0, 0, wb.Width, wb.Height) ;

        bitmap.Height := wb.Height;
        bitmap.Width := wb.Width;

        viewObject.Draw(DVASPECT_CONTENT, 1, nil, nil, Application.Handle, bitmap.Canvas.Handle, @r, nil, nil, 0) ;

        with TJPEGImage.Create do
        try
          Assign(bitmap) ;
          SaveToFile(fileName) ;
        finally
          Free;
        end;
      finally
        bitmap.Free;
      end;
    finally
      viewObject._Release;
    end;
  end;
end;

RefLink : http://delphi.about.com/od/vclusing/a/wb_scren_shot.htm