Link to home
Start Free TrialLog in
Avatar of QC20N
QC20NFlag for Denmark

asked on

Multible use of Webbrowser

Hi

I have a CSV file with alot of ServiceTags to use to browse to www.dell.com to get the Warranty Enddate.

How do I get the info from the Webbrowser and how do I know when webbrowser is finish loading before I can continue?

This is what I have done so far:

 procedure TForm1.Button1Click(Sender: TObject);
var List, LineList : TStringList; I : integer;
begin
  if OpenDialog1.Execute then
  begin
    List := TStringList.Create;
    List.LoadFromFile(OpenDialog1.FileName);
    List.CaseSensitive := True;
    try
      for I := 0 to List.Count - 1 do
      begin
        StatusBar1.Panels[0].Text := 'Processing:' + intTostr(I) + ' of ' + IntToStr(List.Count);
        if pos('Dell',List[I]) <> 0 then
        begin
          LineList := TStringList.Create;
          LineList.Delimiter := ',';
          try
            LineList.DelimitedText := uppercase(StringReplace(StringReplace(List[I],'"','', [rfReplaceAll]),' ','_',[rfRePlaceAll]));
            WebBrowser1.Navigate(DellWebSite + LineList[7]);
          finally
            LineList.Free
          end;
        end;
      end;
    finally
      List.Free;
    end;
  end;
end;

Open in new window

Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

Try this line after Navigate:

WebBrowser1.Navigate(DellWebSite + LineList[7]);
while (WebBrowser1.readystate < READYSTATE_INTERACTIVE) do Application.ProcessMessagess;

Open in new window


or use OnDocumentComplete event:

procedure TForm1.WebDocumentComplete(Sender: TObject;
  const pDisp: IDispatch; var URL: OleVariant);
begin
    while VarIsEmpty(WebBrowser1.Document) do Application.ProcessMessages;
...

Open in new window

Avatar of QC20N

ASKER

How do I get the result of WebBrowser1.Navigate?


And if I use the exampel 2, how do it continue in my For..To..Do loop?
maybe like this:
...
          try
            LineList.DelimitedText := uppercase(StringReplace(StringReplace(List[I],'"','', [rfReplaceAll]),' ','_',[rfRePlaceAll]));
            WebBrowser1.Navigate(DellWebSite + LineList[7]);
            while WebBrowser1.Busy do Application.ProcessMessages;
            while VarIsEmpty(WebBrowser1.Document) do Application.ProcessMessages;
            //do rest here
          finally
            LineList.Free
          end;

Open in new window

Avatar of QC20N

ASKER

I'm sorry.

I need to get the content of the WebBrowser1.document.

How do I search inside WebBrowser1.document?
or can I add the content to a memo1?
Avatar of QC20N

ASKER

Ok. I found this:

function WB_GetHTMLCode(WebBrowser: TWebBrowser; ACode: TStrings): Boolean;
var
  ps: IPersistStreamInit;
  ss: TStringStream;
  sa: IStream;
  s: string;
begin
  ps := WebBrowser.Document as IPersistStreamInit;
  s := '';
  ss := TStringStream.Create(s);
  try
    sa := TStreamAdapter.Create(ss, soReference) as IStream;
    Result := Succeeded(ps.Save(sa, True));
    if Result then ACode.Add(ss.Datastring);
  finally
    ss.Free;
  end;
end;

Open in new window


I can add the content to a memo like this:

 
WB_GetHTMLCode(Webbrowser1, Memo1.Lines);

Open in new window


Is there anyway to clear WebBrowser.Document?

When I do this:

              for c := 0 to memo1.Lines.Count - 1 do
              begin
                p:=pos('NBD ProSupport',memo1.lines[c]);
                if p = 0 then
                  p:=pos('Dell Business',memo1.lines[c]);
                if p > 0 then
                begin
                  sDellEndDate := memo1.lines[c+1];
                  p:=pos('-',sDellEndDate);
                  if p>0 then
                  begin
                    sDellEndDate := copy(sDellEndDate,p-2,10);
                   Break;
                  end;
                end;
              end;

Open in new window


It seems that I get the same date all the time.
look here:

...
          try
            LineList.DelimitedText := uppercase(StringReplace(StringReplace(List[I],'"','', [rfReplaceAll]),' ','_',[rfRePlaceAll]));
            //first clear document
            webBrowser1.Navigate('about:blank') ;
            while WebBrowser1.Busy do Application.ProcessMessages;
            //then go to url
            WebBrowser1.Navigate(DellWebSite + LineList[7]);
            //wait a little
            while WebBrowser1.Busy do Application.ProcessMessages;
            while VarIsEmpty(WebBrowser1.Document) do Application.ProcessMessages;
            //do rest here
          finally
            LineList.Free
          end;

Open in new window

Avatar of QC20N

ASKER

If I do that the content is useless. I have notthing in my Memo1 that I can use.

This is what the memo1 contain.

<HTML></HTML>
ASKER CERTIFIED SOLUTION
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial