Imacros, search source - imacros

I am not expert on imacros search source command, I tried to looking some text on the source page to be extracted..
<div id='keywordsDiv' name='keywordsDiv' class='r-sidebar'>
<dl class="list normal-text">
<dt class="key">Category</dt>
<dd class="value"><a class="black" href="http://www.abcd">abcd</a> </dd>
<dt class="key">Style</dt>
<dd class="value"><a class="black" href="http://www.def.com/">def</a> </dd>
<dt class="key">Location</dt>
<dd class="value"><a class="black" href="http://www.ghi.com/">GHI</a> </dd>
<dt class="key">Keywords</dt>
<dd class="value">
</dd>
</dl>
</div>
How can I extract from source a text from div id=keywordsDiv.
Thank you

I've used the SEARCH command. It uses regex and has worked well for me searching source code. It can really be powerful in automating dynamic pages.
Here is a link:
http://wiki.imacros.net/SEARCH
*Note: I've run into issues with complex regex, I think there are a few flavors or regex and iMacros uses a specific one, plus there are regex limitations.

TAG POS=1 TYPE=DIV ATTR=ID:keywordsDiv EXTRACT=TXT
Try this.

Related

Accordion container with article tag

According to the documentation of F6 we can use the accordion container with something else than a ul tag. Or, I can't get it to work with an article tag.
The problem seems to be caused by the fact that .accordion-title isn't the direct child of .accordion-item. Unfortunately, in my use case, I need to wrap the a tag with the .accordion-title class inside an heading tag.
Does anyone would know how to solve that issue?
Thanks,
Here's an example of my use case :
<div class="accordion" enter code here
data-multi-expand="true"
data-allow-all-closed="true"
data-accordion>
<article class="accordion-item" data-accordion-item>
<header>
<h3>
Group Name
</h3>
</header>
<div class="accordion-content" data-tab-content>
<p>Hello World</p>
</div>
</article>
</div>
As you figured out, it doesn't have to do with the <article> tag but rather that a direct child click trigger is needed.
Example of it working with <article>
https://codepen.io/rafibomb/pen/pGKZYg
Without JS modification, it may not work the way you want it to.

regex repeat group

I am trying to capture the url of the images (how ever many there may be on a specific site. I am able to do so however when I then progress to try an capture other things thereafter the entire thing falls apart. Would greatly appreciate any help.
Working regex:
.(?:src="(http:\/\/website\.bla\.com\/Live.+?)".+?)
Non working
.(?:src="(http:\/\/website\.bla\.com\/Live.+?)".+?).*Status.*\s(Sld|Rtr)
Sample code:
<div ng-class="{
'active': active
}" class="item text-center ng-isolate-scope" ng-transclude="" ng-repeat="slide in slides" active="slide.active">
<img class="image-circle ng-scope" ng-src="http://website.bla.com/Live/photos/FULL/18/134/W3764134_18.jpg" src="http://website.bla.com/Live/photos/FULL/18/134/W3764134_18.jpg">
</div><!-- end ngRepeat: slide in slides --><div ng-class="{
'active': active
}" class="item text-center ng-isolate-scope" ng-transclude="" ng-repeat="slide in slides" active="slide.active">
<img class="image-circle ng-scope" ng-src="http://website.bla.com/Live/photos/FULL/19/134/W3764134_19.jpg" src="http://website.bla.com/Live/photos/FULL/19/134/W3764134_19.jpg">
</div><!-- end ngRepeat: slide in slides --><div ng-class="{
'active': active
}" class="item text-center ng-isolate-scope" ng-transclude="" ng-repeat="slide in slides" active="slide.active">
<img class="image-circle ng-scope" ng-src="http://website.bla.com/Live/photos/FULL/20/134/W3764134_20.jpg" src="http://website.bla.com/Live/photos/FULL/20/134/W3764134_20.jpg">
</div><!-- end ngRepeat: slide in slides -->
</div>
<b class="ng-binding">Status:</b> Sld
For this simple example: use alternates. Please see this.
But this can get complicated if added requirements are to be implemented. In that case you might want to use a HTML parser as in JSoup.
See this one - it is already answered:
With lots of assumptions, you could try this:
src="(http://website\.bla\.com/Live.+?)"(?:(?:[^s]|s[^r]|sr[^c])*?Status.*? (Sld|Rtr))?

Extracting text with imacros

SITUATION: I am finding it difficult to EXTRACT a specific text from a website.
The template example on the iMacros website (http://wiki.imacros.net/Data_Extraction#Data_Extraction_and_Web_Scraping) for
extracting a variable from iMacros is as follows:
TAG POS=1 TYPE=SPAN ATTR=CLASS:bdytxt&&TXT:* EXTRACT=HTM
However in the html code below, the specific element text1 doesn't have a class to specify in the ATTR section. I am specifically trying to extract text1 from the example below:
//This code is within an html page
<div class="class1">
<img class="class2" src="...">
<strong>
text1
</strong>
<br>
<small>text2</small>
<small class="class3">
<br>
<em>text3:</em>
<span>
<a href="..." class="class4">
<small style="color: #aaa; font-size: 80%">text4</small>
text5
</a>
</span>
<br>
<em>text6</em>
text7,
text8
</small>
</div>
What I have tried:
I know that when I record using "Experimental event recording mode" and click on the specific text1 that I get the following code:
EVENT TYPE=CLICK SELECTOR="HTML>BODY>DIV:nth-of-type(5)>DIV>STRONG>A" BUTTON=0
I tested to see if the SELECTOR would work in the EXTRACT code like so:
TAG POS=1 TYPE=SPAN SELECTOR="HTML>BODY>DIV:nth-of-type(5)>DIV>STRONG>A" EXTRACT=TXT
but as you can imagine, it didn't.
QUESTION: Does anyone know how I can extract text1 from the above situation?
Well, there can be several ways to extract this text. For example:
TAG POS=1 TYPE=IMG ATTR=CLASS:"class2"
TAG POS=R1 TYPE=A ATTR=* EXTRACT=TXT
Or if you use 'iMacros for Chrome', here's a solution with the help of selector:
TAG SELECTOR="HTML>BODY>DIV:nth-of-type(5)>DIV>STRONG>A" EXTRACT=TXT

iMacros: How can I click a link in with a specific attribute?

In an iMacros script, how can you trigger a click on a link with a specific attribute? In this case, the link I would like to have clicked has a class of "i-project":
<div data-explore-index="1" >
<div class="i-project-card ">
<a href="/xxxxxxxxxxxxxxxxxx" ">
<span ></span>
</a>
<a href="blablabla" class="i-project">
<img src="https://blabla.jpg">
</a>
</div>
</div>
You should be able to select this link based upon its CLASS attribute:
TAG POS=1 TYPE=A ATTR=CLASS:i-project

Regular expression for exactly one match

I am using the following regular expression in my code editor (sublime text) in order to search for the ASP.NET comments.
<%--.*(\n.*)*--%>
I want this regular expression to stop looking any forward as soon as the first --%> is found. But it keeps looking until the last comment's --%> is found. I have got this idea that i've to use some kind of flag to make it stop as soon as the first --%> but I am unable to figure it out.
Can anyone please tell me how may I modify this regex?
UPDATE
I forgot to post some sample markup. Here it is:
<div class="modal-footer">
<%--<button class="btn" data-dismiss="modal">
Close</button>
<button id="btnAddCountry" class="btn btn-primary" data-dismiss="modal">
Save changes</button>--%>
</div>
</div>
<div class="row-fluid">
<div class="span12">
<div class="box paint_hover">
<div class="title">
<h3>Sale Voucher</span>
</h3>
</div>
<div class="content">
<ul id="tabExample1" class="nav nav-tabs">
<li class="active"><a id="lnkAddEditVoucher" href="#AddEditVoucher" data-toggle="tab">Add/Update Sale Voucher</a></li>
<li><a id="lnkViewVouchers" href="#ViewVouchers" data-toggle="tab">Search Sale Voucher</a></li>
<%-- <li><a id="lnkViewParties" href="#ViewParties" data-toggle="tab">Search Parties</a></li>--%>
</ul>
I just want to match the first comment and not the second one.
You need to make the * quantifiers non-greedy. Usually this is done by adding a ? after them, e.g. .*? instead of just .*.
I've also simplified the regex a bit. Sublime Text supports the (?s) modifier at the beginning of the pattern to make the dot match even newlines:
(?s)<%--.*?--%>
If you prefer matching the newline explicitly:
<%--(.|\n)*?--%>
The problem you seem to have is that you use the greedy version of .*, which matches anything (including --%>). Try using <%--.*?(\n.*?)*?--%> instead to make it non-greedy.