Want to strip some text off html code using imacros

Discussions and Tech Support specific to the iMacros Firefox add-on.
Forum rules
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
miltonbburke
Posts: 4
Joined: Thu Feb 11, 2016 2:12 pm

Want to strip some text off html code using imacros

Post by miltonbburke » Fri Mar 04, 2016 11:56 am

Hello,

I want to scrape valve of "data-thumb" and "data-link" from the following html code

<div style="background-color: rgba(9, 213, 1, 0.85); outline: 1px solid blue;" class="bank-btn" data-source="reddit" data-url="http://i1.nuttit.com//YogaWall/nice_41770456.jpg" data-subreddit="YogaWall" data-title="nice" data-points="-1" data-link="/r/YogaWall/comments/3frimw/nice/" data-num_comments="-1" data-thumb="http://i.imgur.com/lTYfKKt.jpg">BANK IT</div>

I think this needs some imacros+regex right? unfortunately i don't have knowledge of regex and would greatly appreciate any help.

Browser : Mozilla Firefox 44.0.2
OS : Windows 10 Pro
iMacros : iMacros for Firefox : 8.9.6

Regards.
Milton
chivracq
Posts: 9245
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Want to strip some text off html code using imacros

Post by chivracq » Fri Mar 04, 2016 1:49 pm

miltonbburke wrote:Hello,

I want to scrape valve of "data-thumb" and "data-link" from the following html code

<div style="background-color: rgba(9, 213, 1, 0.85); outline: 1px solid blue;" class="bank-btn" data-source="reddit" data-url="http://i1.nuttit.com//YogaWall/nice_41770456.jpg" data-subreddit="YogaWall" data-title="nice" data-points="-1" data-link="/r/YogaWall/comments/3frimw/nice/" data-num_comments="-1" data-thumb="http://i.imgur.com/lTYfKKt.jpg">BANK IT</div>

I think this needs some imacros+regex right? unfortunately i don't have knowledge of regex and would greatly appreciate any help.

Code: Select all

Browser : Mozilla Firefox 44.0.2
OS : Windows 10 Pro
iMacros : iMacros for Firefox : 8.9.6
Regards.
Milton
I don't use/know REGEX either, the easiest way I find and that I use (and I've produced several Examples on the Forum...) is to use 'EVAL()' + 'split()' x2 per Final String that you want to isolate.
The Double Quotes might be a bit problematic as you may have to escape them, if you don't come out, you just leave them in the 'split()' and you can remove them with 'replace()' or 'substr()'...

Search my Posts on "EVAL + split" for Examples. There are 2 Syntaxes for 'split()', you will need the "x[0] / x[1]" one...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
Trax
Posts: 43
Joined: Thu Sep 13, 2012 4:07 pm
Contact:

Re: Want to strip some text off html code using imacros

Post by Trax » Tue Mar 22, 2016 11:32 am

If you can use js and save that link in a variable you could simply replace those with nothing

Code: Select all

var x = '<div style="background-color: rgba(9, 213, 1, 0.85); outline: 1px solid blue;" class="bank-btn" data-source="reddit" data-url="http://i1.nuttit.com//YogaWall/nice_41770456.jpg" data-subreddit="YogaWall" data-title="nice" data-points="-1" data-link="/r/YogaWall/comments/3frimw/nice/" data-num_comments="-1" data-thumb="http://i.imgur.com/lTYfKKt.jpg">BANK IT</div>'

x.replace(/data-thumb=|data-link=.*$/gi, '')
This will remove everything that starts with 'data-thumb=' or 'data-link='. You could probably use EVAL, I have no experience with it since I mostly work in js so can't help with that.
chivracq
Posts: 9245
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Want to strip some text off html code using imacros

Post by chivracq » Tue Mar 22, 2016 2:15 pm

Trax wrote:If you can use js and save that link in a variable you could simply replace those with nothing

Code: Select all

var x = '<div style="background-color: rgba(9, 213, 1, 0.85); outline: 1px solid blue;" class="bank-btn" data-source="reddit" data-url="http://i1.nuttit.com//YogaWall/nice_41770456.jpg" data-subreddit="YogaWall" data-title="nice" data-points="-1" data-link="/r/YogaWall/comments/3frimw/nice/" data-num_comments="-1" data-thumb="http://i.imgur.com/lTYfKKt.jpg">BANK IT</div>'

x.replace(/data-thumb=|data-link=.*$/gi, '')
This will remove everything that starts with 'data-thumb=' or 'data-link='. You could probably use EVAL, I have no experience with it since I mostly work in js so can't help with that.
Yep, could use 'replace()' (with 'EVAL()') as well but it's often a bit "risky" and less "reliable" than 'split()' for long HTML Strings if anything changes in the String, from a Resize for example, and Double Quotes and Forward/Backward Slashes could still be problematic..., oh..., and Spaces as well...

But hum..., this Thread was already from a few weeks ago and the OP never bothered to follow up... :shock:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
Post Reply