I have this code in a website:
<div id="1234">
<li>
text I want to extract
<span>
text I don't want to extract
</span>
</li>
</div>
I'm using this IMACROS code, but it extracts both texts:
TAG XPATH="id('1234')/li[1]" EXTRACT=TXT
I was trying to use text() at the end but get an error.
For your Specific case Shugar's code with some tweaking will work. Split \n and extract [1] :
TAG XPATH="id('1234')/li[1]" EXTRACT=TXT
SET !EXTRACT EVAL("'{{!EXTRACT}}'.split('\\n')[1];")
PROMPT {{!EXTRACT}}
If you want a more General approach you can get li[1] and split by content of span at [0]:
TAG XPATH="id('1234')/li[1]" EXTRACT=TXT
SET !VAR1 {{!EXTRACT}}
SET !EXTRACT NULL
TAG XPATH="id('1234')/li[1]/span" EXTRACT=TXT
SET !EXTRACT EVAL("'{{!VAR1}}'.split('{{!EXTRACT}}')[0];")
PROMPT {{!EXTRACT}}
I suggest just adding one more line in your code:
TAG XPATH="id('1234')/li[1]" EXTRACT=TXT
SET !EXTRACT EVAL("'{{!EXTRACT}}'.split('<span>')[0];")
Related
'part 1 - copy session
SET !EXTRACT_TEST_POPUP NO
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:product-form ATTR=ID:Name EXTRACT=TXT
SET !VAR1 EVAL("\"{{!EXTRACT}}\".replace(/a'/g, \"à\") .replace(/e'/g, \"è\") .replace(/i'/g, \"ì\") .replace(/o'/g, \"ò\") .replace(/u'/g, \"ù\") .replace(/A'/g, \"À\") .replace(/E'/g, \"È\") .replace(/I'/g, \"Ì\") .replace(/O'/g, \"Ò\") .replace(/U'/g, \"Ù\")")
SET !EXTRACT NULL
TAG POS=1 TYPE=A ATTR=TXT:EN
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:product-form ATTR=ID:Locales_1__Name EXTRACT=TXT
SET !VAR2 {{!EXTRACT}}
SET !EXTRACT NULL
WAIT SECONDS=2.0
'part 2 - paste session
TAG POS=1 TYPE=A ATTR=TXT:IT
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:product-form ATTR=ID:Locales_0__Name CONTENT={{!VAR1}}
etc
etc
etc
This is the first part of code I used until now.
Now I need to copy my source text from another tab of chrome in order to make this one the {{!VAR1}} which will be pasted all over the textboxes in another tab.
TAB T=1
FRAME F=2
TAG POS=1 TYPE=DIV ATTR=CLASS:MagicZoomHeader EXTRACT=TXT
SET !VAR1 EVAL("\"{{!EXTRACT}}\".replace(/a'/g, \"à\") .replace(/e'/g, \"è\") .replace(/i'/g, \"ì\") .replace(/o'/g, \"ò\") .replace(/u'/g, \"ù\") .replace(/A'/g, \"À\") .replace(/E'/g, \"È\") .replace(/I'/g, \"Ì\") .replace(/O'/g, \"Ò\") .replace(/U'/g, \"Ù\")")
SET !EXTRACT NULL
TAB T=2
This is the code which extract the text I need from TAB 1.
In order to do this, I write the code using TAB T=1 (to copy and create the first VAR) and TAB T=2 in order to paste the text.
When the macro goes to TAB 2 (starting part 2), suddenly stopped working doing a sort of infinite loading before process this
TAG POS=1 TYPE=A ATTR=TXT:IT
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:product-form ATTR=ID:Locales_0__Name CONTENT={{!VAR1}}
Why this happens? How can I resolve that?
I am creating a macro in which I want to click the anchor element.
The problem with this anchor element is that all the attributes changes randomly after every click.
Below is the anchor link
<a id="bLMa" class="**btn valign-wrapper** pulse **animated** lime accent-2 black-text">**Stаrt**</a>
Items marked between star always remain same. All other items changes continuously.
The location of the anchor changes randomly after every click.
I tried below steps
TAG XPATH="//*[#class="animated"]"
TAG POS=1 TYPE=A ATTR=Class:animated
TAG POS=1 TYPE=A ATTR=TXT:Start
TAG POS=1 TYPE=A ATTR=TXT:*Start*
I always get the same error as Element Not Found.
Please suggest.
You can try combining Attributes to identify the anchor you want to find as per http://wiki.imacros.net/TAG_parameters_explained#Multiple_ATTR_parameters
For your specific example something like
TAG POS=1 TYPE=A ATTR=class:*animated*&&TXT:*Start*
could work, looking for the class animated AND the text Start together in an anchor.
I am trying to match coordinates with 9062 IATA codes that I have compiled in a CSV file. I have tried to use iMacros to input the IATA codes into this website: https://openflights.org/html/apsearch and to extract the coordinates that result.
When executing the macro I do not receive an error, but none of the values are extracted to my designated CSV (the CSV file is blank).
Here is the code:
VERSION BUILD=9030808 RECORDER=FX
TAB T=1
SET !ERRORIGNORE YES
SET !DATASOURCE C:\REDACTED\Desktop\iatasolo.csv
SET !DATASOURCE_COLUMNS 1
SET !LOOP 1
SET !DATASOURCE_LINE {{!LOOP}}
URL GOTO=https://openflights.org/html/apsearch
SET !EXTRACT NULL
TAG POS=1 TYPE=INPUT:CHECKBOX FORM=NAME:searchform ATTR=NAME:iatafilter CONTENT=NO
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:searchform ATTR=NAME:iata CONTENT={{!COL1}}
TAG POS=1 TYPE=INPUT:BUTTON FORM=NAME:searchform ATTR=*
TAG POS=6 TYPE=INPUT:BUTTON ATTR=*
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:searchform ATTR=NAME:y EXTRACT=TXT
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:searchform ATTR=NAME:x EXTRACT=TXT
SAVEAS TYPE=EXTRACT FOLDER=C:\REDACTED\Desktop\macro\test2 FILE=coordinates.csv
Any help would be appreciated.
IATA CODE DATA: https://pastebin.com/4Ez4ids3
I ran your code with the sample data and the website and checked the issues.
List of Issues:
The input file was not getting detected. This was fixed by putting the path in quotes and using the "/" instead of "\" which is used in windows paths.
I have a wait of 2 seconds after the load button is clicked to give time for latitude and longitude to load.
Similarly output should have a different kind of format, this is what worked for me.
Please find below the working code:
VERSION BUILD=9030808 RECORDER=FX
SET !ERRORIGNORE YES
SET !DATASOURCE "C:/Users/Tester/Desktop/file_name.csv"
SET !DATASOURCE_COLUMNS 1
SET !TIMEOUT_STEP 30
SET !EXTRACTDIALOG NO
SET !LOOP 1
SET !DATASOURCE_LINE {{!LOOP}}
URL GOTO=https://openflights.org/html/apsearch
SET !EXTRACT NULL
TAG POS=1 TYPE=INPUT:CHECKBOX FORM=NAME:searchform ATTR=NAME:iatafilter CONTENT=NO
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:searchform ATTR=NAME:iata CONTENT={{!COL1}}
TAG POS=1 TYPE=INPUT:BUTTON FORM=NAME:searchform ATTR=*
TAG POS=6 TYPE=INPUT:BUTTON ATTR=*
WAIT SECONDS=1
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:searchform ATTR=NAME:iata EXTRACT=TXT
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:searchform ATTR=NAME:y EXTRACT=TXT
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:searchform ATTR=NAME:x EXTRACT=TXT
SAVEAS TYPE=EXTRACT FOLDER="C:\\Users\\Tester\\Desktop" FILE=coordinates.csv
I'm extracting text from a website:
TAG POS=1 TYPE=TD ATTR=TXT:*<SP>(View<SP>Listing) EXTRACT=TXT
but later i want to use only what is before the VIEW LISTING text so i want to subtract this from the EXTRACT, how to do it?
I tried this:
SET !CLIPBOARD {{!EXTRACT}}
ADD !CLIPBOARD -<SP>(View<SP>Public<SP>Listing)
and this:
SET !EXTRACT EVAL("var s=\"{{!EXTRACT}}\"; s.slice(\"'\", -22);")
(found both on stack) but none of these work. also i can't extract without this text in the first place (the site is built this way)
Okay stupid mistake in syntax, found the solution:
SET !EXTRACT EVAL("var s=\"{{!EXTRACT}}\"; s.slice(\"\", -22);")
I have this code that checks for text on a page and then saves the text to a csv:
TAG POS=1 TYPE=DIV ATTR=TXT:* EXTRACT=TXT
SAVEAS TYPE=EXTRACT FOLDER=C:\test FILE=test.csv
Is it possible to add my own text to the extracted TXT, I tried this:
TAG POS=1 TYPE=DIV ATTR=TXT:*+{{!CLIPBOARD}} EXTRACT=TXT
SAVEAS TYPE=EXTRACT FOLDER=C:\test FILE=test.csv
So, this time I want it to save to the CSV as "textInDiv","clipboardValue"
Thanks.
TAG POS=1 TYPE=DIV ATTR=TXT:* EXTRACT=TXT
ADD !EXTRACT {{!CLIPBOARD}}
SAVEAS TYPE=EXTRACT FOLDER=C:\test FILE=test.csv
http://wiki.imacros.net/ADD
to save to the CSV as "textInDiv","clipboardValue", try this:
TAG POS=1 TYPE=DIV ATTR=TXT:* EXTRACT=TXT
SET !EXTRACT {{!EXTRACT}}[EXTRACT]{{!CLIPBOARD}}
SAVEAS TYPE=EXTRACT FOLDER=C:\test FILE=test.csv