Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
extract values from webpage
extract values from webpage
Hey,
How to pick up values from webpage, if i have the XPATH of the nodes? using MiniBrowser .
is there a better Demo to try and do it?
i found that a selector can be used like this
var dates = $$('div',document.querySelectorAll);
for(each in dates){console.log(dates[each].innerText);}
the 'div' you can get with the chrome devTools. highlight the item, and right click on it, copy then copy selector.
however, I don't know how to interface the javascript with the delphi, except call Chrominum1.ExecuteJavaScript()
How to pick up values from webpage, if i have the XPATH of the nodes? using MiniBrowser .
is there a better Demo to try and do it?
i found that a selector can be used like this
var dates = $$('div',document.querySelectorAll);
for(each in dates){console.log(dates[each].innerText);}
the 'div' you can get with the chrome devTools. highlight the item, and right click on it, copy then copy selector.
however, I don't know how to interface the javascript with the delphi, except call Chrominum1.ExecuteJavaScript()
- salvadordf
- Posts: 4304
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: extract values from webpage
Hi,
CEF allows you to send and receive information between the main browser process and the renderer process.
You can use several ways to send that information and most of them are described in the /demos/Delphi_VCL/DOMVIsitor and /demos/Delphi_VCL/JavaScript/JSExtension demos.
Read the code comments in those demos for more information.
CEF allows you to send and receive information between the main browser process and the renderer process.
You can use several ways to send that information and most of them are described in the /demos/Delphi_VCL/DOMVIsitor and /demos/Delphi_VCL/JavaScript/JSExtension demos.
Read the code comments in those demos for more information.
Re: extract values from webpage
Thank you so much. I will read those demos and post my understandings.
Re: extract values from webpage
a must know is :
https://magpcss.org/ceforum/viewtopic.php?f=10&t=634
document.body.innerHTML ='value' ;
to clear the webpage.
https://magpcss.org/ceforum/viewtopic.php?f=10&t=634
which means you cannot make the javascript change the page likeThe DOM API exposed by Chromium is read-only with the exception of adding listeners. CEF exposes this same API via the CefFrame::VisitDOM method. If you want to manipulate the DOM directly via C++ it will be necessary to use WebKit interfaces directly.
document.body.innerHTML ='value' ;
to clear the webpage.
Re: extract values from webpage
this
cause this exception
Debug Output:
[0804/113627.290:INFO:CONSOLE(10)] "Uncaught SyntaxError: Cannot use import statement outside a module", source: about:blank (10)
Process DOMVisitor.exe (4792)
when i try to do this
Code: Select all
import $ from 'jquery';
Debug Output:
[0804/113627.290:INFO:CONSOLE(10)] "Uncaught SyntaxError: Cannot use import statement outside a module", source: about:blank (10)
Process DOMVisitor.exe (4792)
when i try to do this
Code: Select all
function TDOMVisitorFrm.ReadScript: string;
var
FileStream:TFileStream;
StringStream:TStringStream;
begin
FileStream := TFileStream.Create('C:\folder\parse.js',fmOpenRead);
stringStream := TStringStream.Create;
stringStream.LoadFromStream(FileStream);
result := StringStream.DataString;
fileStream.Free;
stringstream.Free;
end;
procedure TDOMVisitorFrm.Chromium1ContextMenuCommand(Sender: TObject;
....
MINIBROWSER_CONTEXTMENU_GETDATA: //new event
begin
RawLine := ReadScript;
frame.ExecuteJavaScript(RawLine,'about:blank',0);
showmessage(RawLine);
end;
Re: extract values from webpage
using the JSEval result in
what am I missing?
which means the jquery is not loaded. here too.Uncaught ReferenceError: $$ is not defined
what am I missing?
- salvadordf
- Posts: 4304
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: extract values from webpage
I'm sorry but I'm not a JS expert and I don't have an answer but the error message "Uncaught SyntaxError: Cannot use import statement outside a module" suggests that this is a pure JavaScript issue.
Perhaps this could be helpful :
https://exerror.com/uncaught-syntaxerror-cannot-use-import-statement-outside-a-module-when-importing-ecmascript-6/
Perhaps this could be helpful :
https://exerror.com/uncaught-syntaxerror-cannot-use-import-statement-outside-a-module-when-importing-ecmascript-6/
Re: extract values from webpage
the easiest way to get a value from the browser is this:
https://www.briskbard.com/forum/viewtopic.php?p=2886&sid=dcfc576df0a494604148f07b74292370#p2886
and use jsRTTIExtention
limited to 1000 charachters.
https://www.briskbard.com/forum/viewtopic.php?p=2886&sid=dcfc576df0a494604148f07b74292370#p2886
and use jsRTTIExtention
limited to 1000 charachters.
Re: extract values from webpage
now how do i get a value from the browser if using the SubProcess?
the procedure
the procedure
sets the value but i want to get a value.GlobalCEFApp_OnContextCreated
- salvadordf
- Posts: 4304
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: extract values from webpage
You can execute custom JavaScript code from the main browser process and the render process to set values in the DOM.
See the DOMVIsitor demo to know how to send a message to the render process. Then use the "frame" parameter in GlobalCEFApp_OnProcessMessageReceived to call ExecuteJavaScript in the render process like this :
See the DOMVIsitor demo to know how to send a message to the render process. Then use the "frame" parameter in GlobalCEFApp_OnProcessMessageReceived to call ExecuteJavaScript in the render process like this :
Code: Select all
frame.ExecuteJavaScript(YourJSCode, frame.url, 0);