Asger-P
Asger-P

Reputation: 31

c++ extract text from edge browser as if using Ctrl+A and Ctrl+C

I am currently extracting text from a website using SendInput Ctrl+A and Ctrl+C then I keep an eye on the clipboard and extract the text. This requires that the EdgeBrowser window have focus, it is that part that doesn't work for my program because the text usually change once every minute.

So my question is: Is there a way to extract the visible text from an EdgeBrowser window without it having the focus ?

P.s. The Edge Browser is embedded into my app via a dll. (c++ Builder component)

Upvotes: 0

Views: 147

Answers (1)

Asger-P
Asger-P

Reputation: 31

It only takes two lines of code when using the C++Builder component TEdgeBrowser

One for executing a script on the webpage:

EdgeBrowser->ExecuteScript(L"document.body.innerText");

And then the result is returned in the ExecuteScript event:

void __fastcall TForm1::EdgeBrowserExecuteScript(TCustomEdgeBrowser *Sender, HRESULT AResult, const UnicodeString AResultObjectAsJson)
{
   Memo1->Text = Sysutils::StringReplace( AResultObjectAsJson, L"\\n", L"\r\n", TReplaceFlags()<<rfReplaceAll );
  
}

The StringReplace is due to a bug in the JSon string.

Upvotes: 0

Related Questions