如何使用imacros xpath提取特定文本 [英] How to extract specific text with imacros xpath
本文介绍了如何使用imacros xpath提取特定文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在网站上有以下代码:
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>
我正在使用此IMACROS代码,但它同时提取了两个文本:
I'm using this IMACROS code, but it extracts both texts:
TAG XPATH="id('1234')/li[1]" EXTRACT=TXT
我试图在最后使用text(),但出现错误.
I was trying to use text() at the end but get an error.
推荐答案
对于您的特定案例 Shugar进行一些调整的代码将起作用.分割 \ n
并提取 [1]
:
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}}
如果您想要更常规方法,则可以获取 li [1]
并按 [0]
:
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}}
这篇关于如何使用imacros xpath提取特定文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文