iMacros get text from HTML list - imacros

I am using iMacros to try and get the text from each list item. My simple HTML looks like this...
<ul id="fruit_list">
<li>Apple</li>
<li>Pear</li>
<li>Banana</li>
<li>Grape</li>
</ul>
And my iMacros script like this..
TAB T=1
URL GOTO=file:///C:/test.html
TAG POS=1 TYPE=UL ATTR=ID:fruit_list EXTRACT=TXT
The result I get back is ...
AppleApplePearAppleApplePearBananaAppleApplePearAppleApplePearBananaGrape
When what I am expecting is...
Apple Pear Banana Grape
Can anyone show me what I am doing wrong?

There seems to be no easy EXTRACT Option that covers unordered lists that way... The simplest way to go about this is probably to extract the HTML code and parse that in Javascript with SET/EVAL.
It could look like this
TAG POS=1 TYPE=UL ATTR=ID:fruit_list EXTRACT=HTM
SET neat_list EVAL("var e_s = '{{!EXTRACT}}'; e_s.substring(e_s.indexOf('<li>'), e_s.lastIndexOf('<\\/li>')).replace(/(<li>|<\\/li>)/g, '').replace(/ +/g, ' ');")
PROMPT {{neat_list}}
Using Regex to drop all the HTML Tags and additional whitespace to just keep the LI-Item Data you wanted.

Related

IMacros Extract, How to extract title from html code using IMacros and RegEx?

I want to extract the title from an HTML code, using Imacros and RegEx, the title is wrapped in some code that I want to filter out, I don't know how to use EVAL neither RegEx, I just found some RegEx that worked with my code, so it extracts the title from other codes,
but I am not sure how to use it with Imacros, appreciate it if anyone knows how to make it work, whether with RegEx or other ways.
Here is the html part:
<a data-test-id="search-guide" href="" title="Search for "skin care routine""><div
class="Jea Lfz XiG fZz gjz qDf zI7 iyn Hsu" style="white-space: nowrap; background-color: rgb(115,
115, 115);"><div class="tBJ dyH iFc MF7 erh tg7 IZT mWe">Routine</div></div></a>
the part from the title I want is: skin care routine
the RexEx part that I use:
title="Search for "([^"]*)"
and here is my Imacros:
TAG POS=3 TYPE=a ATTR=data-test-id:search-guide EXTRACT=href
SET !VAR1 EVAL('s = '{{!EXTRACT}}'[title='Search for "([^']*)"]')
PROMPT {{!EXTRACT}}
I get an error on the EVAL Line:
wrong format of SET command, line 15 (Error code: -910)
OK, I got it working, Here is the working code:
TAG POS=3 TYPE=A ATTR=data-test-id:search-guide EXTRACT=TITLE
SET !VAR1 EVAL("\"{{!EXTRACT}}\".substr(10,100);")
PROMPT {{!VAR1}}
Several "Mistakes" in your Script and Approach indeed...
'EXTRACT=HREF' won't get you anywhere, => simply use directly 'EXTRACT=TITLE' + 'EVAL()' (with 'replace()' if you don't mind keeping the Double Quotes, or 'split()' if you want to get rid of them)...
(Much easier without 'RegEx' anyway...)
(Spell "iMacros" correctly (x5) + Add a Question Mark to your Title (you are not sharing a 'HowTo'...) + Mention your FCI if you need me to "elaborate" in more Details...)

Extract dynamic content with iMacros

I'm entirely new to iMacros, and I'm trying to get iMacros to extract the email address that appears when you click "reply" on ads like these. (Link is "dead"...)
The only thing I have is:
VERSION BUILD=10021450
URL GOTO=https://losangeles.craigslist.org/sfv/res/d/need-extra-money/7027377618.html
TAG POS=1 TYPE=BUTTON ATTR=TXT:reply
I have tried simply using wildcards, which doesn't work.
I found the answer somehow:
TAG POS=1 TYPE=INPUT ATTR=CLASS:anonemail EXTRACT=TXT

iMacro text field Inputting issue

hopefully you can help me. This is my attempt at using a macro to add text into a text field on a website.​
This is my current iMacro code, which opens the text box (by clicking a couple of buttons) however doesn't activate the text box nor add any text into it:
VERSION BUILD=9030808 RECORDER=FX
TAB T=1
URL GOTO=https://datatron.l2inc.com/#resources?selected=brandTab5229&brands=5229
TAG POS=1 TYPE=BUTTON ATTR=TXT:Create<SP>New<SP>Resources<SP>for<SP>Brand
TAG POS=1 TYPE=BUTTON ATTR=ID:add-urls
PROMPT "Please enter something:" !VAR1
TAG POS=1 TYPE=TEXTAREA ATTR=CLASS:form-control CONTENT={{!VAR1}}
The last lines are my attempt adding my own text (VAR1) into the textbox. The relevant html code (created by javascript) simply reads as this:
​<textarea class="form-control urls-textarea" rows="10" placeholder="irrelevant placeholder text"></textarea>
Do you know where I am going wrong??
Best regards
Roman
Try to record your manual typing wlth 'Experimental event recording mode'.
Taking into account the html code you provided, the event command may look like:
EVENTS TYPE=KEYPRESS SELECTOR="textarea[class='form-control urls-textarea']" CHARS={{!VAR1}}

Get number of elements in Imacros

There are 10 li tags in an html. I need the number to use it with a loop in a vbs file.
I tried this simple code but it didn't work, even in firefox extension
URL GOTO=javascript:document.getElementsByClassName('movableListItem').length;
One can try the code below to set the built-in variable !EXTRACT to the number of image tags in a document. And your question is similar.
SET !EXTRACT_TEST_POPUP NO
URL GOTO=javascript:{window.document.getElementsByTagName("img").length}
URL GOTO=javascript:{window.history.back()}
TAG POS=1 TYPE=HTML ATTR=* EXTRACT=TXT
BACK
Imacros can do it but you need to make a loop and catch the first error. It's kinda complicated for just this simple question but in Selenium IDE just do this:
Command: storeCssCount
Target : css=a
Value : n
And that's all. A single line of code

Imacros help, script was working but not now

This line was working before but now it doesn't extract the text, I guess this is happening because it is clicking inside the box. This only happen when I use Firefox, using Internet Explorer is ok.
VERSION BUILD=8021970
TAB T=1
TAB CLOSEALLOTHERS
URL GOTO=http://www.fakemailgenerator.com/
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:emailForm ATTR=ID:fName&&VALUE:* EXTRACT=TXT
it looks like the value you need is disappear when imacros tries to scrape it, but you can use this code to get email:
URL GOTO=http://www.fakemailgenerator.com/
TAG POS=1 TYPE=span attr=id:cxtEmail EXTRACT=TXT
or you can scrape htm of your tag and parse it to get value attribute