Reputation: 326
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.
Upvotes: 0
Views: 2716
Reputation: 655
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}}
Upvotes: 4
Reputation: 5299
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];")
Upvotes: 0