Search code examples
imacros

Extract htm text for differents tags in imacros


I want to extract the htm text for a particular tags, so here is the link for which I want to extract their htm text I use this tag to extract the entire htm text for a particular record

TAG POS=2 TYPE=div ATTR=class:m-srp-card<SP>SRCard&&TXT:* EXTRACT=HTM

So by just changing the POS=? number I get the htm text for every record, but in this case the attribute class:m-srp-card<SP>SRCard changes for different position. for example in when POS=3 it tags 4th record instead of 3rd. Is there any alternative by which I can just change the POS number and get the htm record?

Thanks

Domnick.


Solution

  • I checked the link you provided, the problem is with the attribute selector as you mentioned, the reason you are facing this issue is because it exactly checks for the class in the div to be m-srp-card<SP>SRCard but in some of the elements there are other classes which are present, my solution for this will be to add a wildcard (*) at the end of the classes, so that it is flexible and allows other classes to be present.

    VERSION BUILD=1001 RECORDER=CR
    SET !ERRORIGNORE YES
    SET !LOOP 1
    TAG POS={{!LOOP}} TYPE=div ATTR=class:m-srp-card<SP>SRCard* EXTRACT=HTM
    

    I have also setup a loop which can be rerun to iterate through the divs, also included the second line which will handle cases where the particular tag is not present in the html.

    Please let me know if this fixes your issue!