extract text from Element with non-fixed location

Discussions and Tech Support related to website data extraction, screen scraping and data mining using iMacros.
Forum rules
iMacros EOL - Attention!

The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.

Thank you again for your business and support.

Sincerely,
The Progress Team

Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
User avatar
vardipoor.m
Posts: 34
Joined: Sun Jan 17, 2021 8:58 am

extract text from Element with non-fixed location

Post by vardipoor.m » Thu Feb 04, 2021 11:30 am

hi
i use imacros browser 12.5 and windows 10 pro x64

i want to extract some text from a website
Description of text and square:
Every time I enter the site, the location of each square (only the squares, not the text inside them), which includes reinvest, withtraw, etc., changes.
The square location changes every time I enter the site and I can not extract the text correctly. I want to extract the number inside the square corresponding to doge. Inside the attached photo, it is written 0.825348080509353. This number is constantly increasing.
I used the Extraction Wizard feature and got the following code. (Click on number)

Code: Select all

TAG POS=2 TYPE=H4 ATTR=CLASS:cloud-percent EXTRACT=TXT
This code works fine. As long as the location does not change.
But when its location changes and xmr, for example, takes its place, the number corresponding to xmr (returns 0.00000000000000)
I even tried to select the doge text as an anchor title so that

Code: Select all

TAG POS=2 TYPE=H4 ATTR=CLASS:m-2 EXTRACT=TXT
Again, this code works as long as the location does not change
i update this code as following but get not found error

Code: Select all

TAG POS=2 TYPE=H4 ATTR=CLASS:m-2&&TXT:DOGE EXTRACT=TXT
and this is the doge text html tag

Code: Select all

<h4 class="m-2">DOGE</h4>
What is the solution now?
I hope the explanation is complete.
Attachments
Screenshot 2021-02-04 145532.jpg
Thanks to the clever and clean administrator of this forum
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: extract text from Element with non-fixed location

Post by chivracq » Thu Feb 04, 2021 10:36 pm

vardipoor.m wrote:
Thu Feb 04, 2021 11:30 am
hi
i use

Code: Select all

imacros browser 12.5 and windows 10 pro x64
i want to extract some text from a website
Description of text and square:
Every time I enter the site, the location of each square (only the squares, not the text inside them), which includes reinvest, withtraw, etc., changes.
The square location changes every time I enter the site and I can not extract the text correctly. I want to extract the number inside the square corresponding to doge. Inside the attached photo, it is written 0.825348080509353. This number is constantly increasing.

I used the Extraction Wizard feature and got the following code. (Click on number)

Code: Select all

TAG POS=2 TYPE=H4 ATTR=CLASS:cloud-percent EXTRACT=TXT
This code works fine. As long as the location does not change.
But when its location changes and xmr, for example, takes its place, the number corresponding to xmr (returns 0.00000000000000)
I even tried to select the doge text as an anchor title so that

Code: Select all

TAG POS=2 TYPE=H4 ATTR=CLASS:m-2 EXTRACT=TXT
Again, this code works as long as the location does not change
i update this code as following but get not found error

Code: Select all

TAG POS=2 TYPE=H4 ATTR=CLASS:m-2&&TXT:DOGE EXTRACT=TXT
and this is the doge text html tag

Code: Select all

<h4 class="m-2">DOGE</h4>
What is the solution now?
I hope the explanation is complete.

Alright, good Quality for this Thread, very good...! :D

Like already mentioned in some other Thread of yours, I "think" I have some "quick and easy" Solution, if I understood the HTML Structure "correctly" from your Screenshot and the mini-Scripts you included...

=> Try this one...:

Code: Select all

TAG POS=1 TYPE=H4 ATTR=CLASS:m-2&&TXT:DOGE EXTRACT=TXT
SET !EXTRACT NULL
TAG POS=R1 TYPE=H4 ATTR=CLASS:cloud-percent EXTRACT=TXT
SET Doge_Value {{!EXTRACT}}
PROMPT DOGE_Value:<SP>_{{Doge_Value}}_
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
User avatar
vardipoor.m
Posts: 34
Joined: Sun Jan 17, 2021 8:58 am

Re: extract text from Element with non-fixed location

Post by vardipoor.m » Fri Feb 05, 2021 7:49 am

thanks

Why do all your answers work? :)
I wrote the same code. By comparing the two codes, I realized what was wrong with my code. In my code the value was pos=2 and in your code the value was pos=1.
my code

Code: Select all

TAG POS=2 TYPE=H4 ATTR=CLASS:m-2&&TXT:DOGE EXTRACT=TXT
your code

Code: Select all

TAG POS=1 TYPE=H4 ATTR=CLASS:m-2&&TXT:DOGE EXTRACT=TXT
Because of this my code did not work.
Apparently it should be pos=1 for the anchor.
Thanks to the clever and clean administrator of this forum
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: extract text from Element with non-fixed location

Post by chivracq » Fri Feb 05, 2021 8:41 am

vardipoor.m wrote:
Fri Feb 05, 2021 7:49 am
thanks

Why do all your answers work? :)
I wrote the same code. By comparing the two codes, I realized what was wrong with my code. In my code the value was pos=2 and in your code the value was pos=1.
my code

Code: Select all

TAG POS=2 TYPE=H4 ATTR=CLASS:m-2&&TXT:DOGE EXTRACT=TXT
your code

Code: Select all

TAG POS=1 TYPE=H4 ATTR=CLASS:m-2&&TXT:DOGE EXTRACT=TXT
Because of this my code did not work.
Apparently it should be pos=1 for the anchor.
>>>
vardipoor.m wrote:
Fri Feb 05, 2021 7:49 am
Why do all your answers work? :)

I'll take that as a Compliment, ah-ah...! :P :twisted: :wink:

>>>

Yeah well, "I wrote the same code."..., 'POS=1' <> 'POS=2' is not the same for iMacros, ah-ah...! :wink:

=> I can see 4 "Boxes" from your Screenshot, => "XMR" + "DOGE" + Names not visible for the next 2 below, but they apparently share the same HTML Structure with the same 'CLASS' Attributes for the "cloud-percent" and Name Elements, so it was 'POS=2' for the "Case" from your Screenshot with "DOGE" being the 2nd Box, if you only use the 'CLASS' Attr to identify/locate/tag both of them...

But the "Purpose" of using 'Relative Positioning' is to try to get the lowest 'POS' Nb possible for the 'Anchor', and optimally => 'POS=1', ... which can be achieved by combining both the 'CLASS' + the 'TXT' Attributes together.

What would also probably work would be to use only the 'TXT' (=DOGE) Attr...:

Code: Select all

'TAG POS=1 TYPE=H4 ATTR=CLASS:m-2&&TXT:DOGE EXTRACT=TXT
TAG POS=1 TYPE=H4 ATTR=TXT:DOGE EXTRACT=TXT
SET !EXTRACT NULL
TAG POS=R1 TYPE=H4 ATTR=CLASS:cloud-percent EXTRACT=TXT
SET Doge_Value {{!EXTRACT}}
PROMPT DOGE_Value:<SP>_{{Doge_Value}}_
... But hum, I think it could "easily" get broken and it is "safer" to use the 'CLASS' Attr also with it to enforce the 'POS=1' on the 'Anchor' more reliably...

The "fake" 'EXTRACT' on the 'Anchor' is btw maybe not needed, (I can't tell from only a Screenshot), it is only needed if the "DOGE" 'H4' Text Element is Clickable, if it's "only" a (Display) Text Element, then the 'EXTRACT' is not needed and was only meant to prevent iMacros from clicking on that Element... :idea:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
User avatar
vardipoor.m
Posts: 34
Joined: Sun Jan 17, 2021 8:58 am

Re: extract text from Element with non-fixed location

Post by vardipoor.m » Fri Feb 05, 2021 6:15 pm

Yes, Dodge is just text and non-clickable and there was no need to extract, but I also used Dodge text in the output.
Thankful
Thanks to the clever and clean administrator of this forum
Post Reply