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.
X11
Posts: 49 Joined: Thu Jul 25, 2019 10:15 am
Post
by X11 » Thu Aug 29, 2019 11:10 am
Tell me please, how to find tel nubmer?
What to specify in parameter "NodeID"?
Code: Select all
procedure SimpleNodeSearch(const aDocument: ICefDomDocument; const frame: ICefFrame; const NodeID: string);
var
TempNode: ICefDomNode;
msg: ICefProcessMessage;
begin
try
if aDocument <> nil then
begin
TempNode := aDocument.GetElementById(NodeID);
msg := TCefProcessMessageRef.New(msg_for_chromium);
if TempNode <> nil then
begin
msg.ArgumentList.SetString(0, 'Node found: ' + NodeID);
msg.ArgumentList.SetString(1, 'Node name: ' + TempNode.Name);
msg.ArgumentList.SetString(2, 'ElementInnerText: ' + TempNode.ElementInnerText);
msg.ArgumentList.SetString(3, 'ElementTagName: ' + TempNode.ElementTagName);
end
else
msg.ArgumentList.SetString(0, 'ERROR. Node not found: ' + NodeID);
frame.SendProcessMessage(PID_BROWSER, msg);
end;
except
on e : exception do
if CustomExceptionHandler('SimpleNodeSearch', e) then raise;
end;
end;
for example
page url doska.plus/chita/search/nedvizhimost/prodazha-nedvizhimosti/prodazha-kvartir/prodam-3-komn-kvartiru-49440.html
thanx
salvadordf
Posts: 4565 Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:
Post
by salvadordf » Thu Aug 29, 2019 12:03 pm
You can only use GetElementById to search HTML elements that have an "
id " attribute.
In this example you can call aDocument.GetElementById('myHeader') to get the H1 element :
Code: Select all
<html><body><h1 id="myHeader">Hello World!</h1></body></html>
X11
Posts: 49 Joined: Thu Jul 25, 2019 10:15 am
Post
by X11 » Thu Aug 29, 2019 12:16 pm
OK, then maybe during an iteration over the DOM?
Code: Select all
procedure SimpleDOMIteration(const aDocument: ICefDomDocument; const frame: ICefFrame);
var
TempHead, TempChild : ICefDomNode;
msg: ICefProcessMessage;
attrList: TStrings;
begin
try
if aDocument <> nil then
begin
TempHead := aDocument.Body;
if TempHead <> nil then
begin
TempChild := TempHead.FirstChild;
while TempChild <> nil do
begin
Msg := TCefProcessMessageRef.New(msg_for_chromium);
if TempChild.ElementInnerText = '' then
begin
TempChild := TempChild.NextSibling;
Continue;
end;
msg.ArgumentList.SetString(0, 'name: ' + Trim(TempChild.Name));
msg.ArgumentList.SetString(1, 'TagName: ' + Trim(TempChild.ElementTagName));
attrList := TStringList.Create;
try
TempChild.GetElementAttributes(attrList);
msg.ArgumentList.SetString(2, 'attrList: ' + attrList.Text);
finally
attrList.DisposeOf;
end;
msg.ArgumentList.SetString(3, 'InnerText: ' + Trim(TempChild.ElementInnerText));
msg.ArgumentList.SetString(4, '**********************');
frame.SendProcessMessage(PID_BROWSER, msg);
TempChild := TempChild.NextSibling;
end;
end;
end;
except
on e : exception do
if CustomExceptionHandler('SimpleDOMIteration', e) then raise;
end;
end;
salvadordf
Posts: 4565 Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:
Post
by salvadordf » Thu Aug 29, 2019 12:22 pm
If that element doesn't have an ID attribute search with an iteration over the DOM using the functions ICEFDomNode.HasElementAttribute and ICEFDomNode.GetElementAttribute on each node to find what you are looking for.
X11
Posts: 49 Joined: Thu Jul 25, 2019 10:15 am
Post
by X11 » Thu Aug 29, 2019 12:29 pm
then I Copy InnerHTML in Mozilla Firefox, I see "<span><a href="tel:+xxxxxxx0">+xxxxxxx0</a></span>"
But
returns without tags "
<span> " or "
<a href= "
X11
Posts: 49 Joined: Thu Jul 25, 2019 10:15 am
Post
by X11 » Thu Aug 29, 2019 12:41 pm
prn scr
http://prntscr.com/oz52ad
Code: Select all
if TempChild.HasElementAttribute('href') then
msg.ArgumentList.SetString(4, 'href: ' + Trim(TempChild.GetElementAttribute('href')));
but code can`t found attribute "href"
salvadordf
Posts: 4565 Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:
Post
by salvadordf » Thu Aug 29, 2019 12:48 pm
Use ICEFDomNode.AsMarkup to get the contents of this node as markup .
Use ICEFDomNode.ElementInnerText to get the inner text of the element.
If TempChild really is the "A" element and not a parent or sibling node then TempChild.HasElementAttribute('href') should be TRUE, unless there's a bug in Chromium.
X11
Posts: 49 Joined: Thu Jul 25, 2019 10:15 am
Post
by X11 » Thu Aug 29, 2019 12:59 pm
I forgot about recursion
X11
Posts: 49 Joined: Thu Jul 25, 2019 10:15 am
Post
by X11 » Thu Aug 29, 2019 1:02 pm
Is your "SimpleDOMIteration()" example recursively traversing the DOM tree? Or not?
salvadordf
Posts: 4565 Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:
Post
by salvadordf » Thu Aug 29, 2019 4:28 pm
SimpleDOMIteration only iterates through the first generation child elements of the HEAD element and it doesn't goes any further. It's not recursive.