1

I have a small problem with Chrome embedded in Delphi.
I would like to get the text of the page loaded from a list of URLs in ListBox (loop).

It seems easy ! My code looks like :

for i := 0 to Form1.ListBox1.Items.Count - 1 do
begin
  // Load URL
  Form1.Chromium1.Browser.MainFrame.LoadUrl(Form1.ListBox1.Items[i]);

  // Put text in StringList
  s := TStringList.Create;
  s.Text := Trim(Form1.Chromium1.Browser.MainFrame.Text);

  // Save with random name
  s.SaveToFile(ExtractFilePath(Application.Exename) +
    IntToStr(RandomRange(1000, 9999)) + '.txt');
end;

The loop works, but take just 1-2 seconds and files saved are empty...
In reality the loop is finished before that pages are loaded :S
It should wait the end of page loading.

Does someone have an idea about that ?
Thanks in advance ! :)

Beny

TLama
  • 75,147
  • 17
  • 214
  • 392
Beny
  • 890
  • 2
  • 15
  • 26
  • 1
    Wouldn't it be easier just to download the pages straight to files without the need for a Chrome browser? – David Heffernan Jan 30 '12 at 20:33
  • Yes it's possible (via Indy for example), but the parsing will be too long then. Getting the "visual" text via Chrome is fast and the parsing will be light then ;) Beny – Beny Jan 30 '12 at 20:35
  • 4
    I guess you need to wait for the `MainFrame` to be ready. As it's said [`here`](http://stackoverflow.com/a/7456236/960757), you might try to handle the `OnLoadEnd` event and save your files there (it should be the time when the loading is finished). – TLama Jan 30 '12 at 20:58
  • Thanks for the link, I'll give a look. Beny – Beny Jan 30 '12 at 21:06
  • Hello everybody, I have "solved" my problem by putting a boolean value to False when Chromium1LoadStart, and to True when Chromium1LoadEnd. Then in my loop I use a Repeat Until. It's a bit rustic but it works :D Hope it will help. Beny – Beny Feb 01 '12 at 13:29

0 Answers0