【问题标题】:Extract, create and append using xpath and telegram instant view使用 xpath 和电报即时视图提取、创建和附加
【发布时间】:2019-02-20 12:10:59
【问题描述】:
<iframe src="https://expmle.com/subdirectory/sample_title" />

如何使用XPathTelegram Instant view 函数从上面的代码createappend&lt;a&gt; 下方?

<a href="https://expmle.com/subdirectory/sample_title">sample_title</a>

我想提取整个src最后一部分,并使用它们来创建&lt;a&gt; 标签。

任何建议将不胜感激:)

【问题讨论】:

    标签: xpath telegram xpath-1.0 instant-view


    【解决方案1】:

    这应该可以正常工作。

    <a>: //iframe # Find iframe and convert it to <a>
    
    @set_attr(href, ./@src) # Set href attribute from src
    
    $anchor # Create variable for current <a>
    @set_attr(text, ./@href) # We set new attribute for link which will processed by @match function, then @text attribute will be replaced by result of the @match
    @match("\\w+_\\w+"): $@/@text # Now we find our future name of the link "sample_name" (this function will replace all in @text by our new name
    
    @prepend(@text): $anchor # And then put this name to his $anchor
    

    【讨论】:

    • 非常感谢,除了最后一行外,它几乎可以工作。 $@ 是一个属性节点,我不知道为什么,但 @prepend_to 没有将其添加为 &lt;a&gt; 的文本。
    • 我试图使用@prepend($@): $anchor,但它将$@解析为字符串而不是变量:(你怎么看?
    • 谢谢,我需要将$@/@text 更改为$$/@text$anchor/@text 才能得到结果。
    • 酷!祝你比赛好运:)
    【解决方案2】:
    # append <a> tag below
    @after(<a>, href, ./@src, content, ./@src): //iframe
    
    # take everything after the last slash
    @match("[^\/]+$", "1"): $@/@content
    
    # move the attribute inside the tag
    @append(@content): $@
    

    如果最后一个$@ 不起作用,只需为&lt;a&gt; 定义一个变量。

    【讨论】:

    • 非常感谢,是的,正如您所说,我需要为&lt;a&gt; 定义一个变量,我还将您的正则表达式更改为"[^\/]+$" 并从@987654327 中删除点斜杠(./) @ 现在它工作正常。
    • @Alizadeh118 那你能改一下最佳答案吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-16
    • 1970-01-01
    • 1970-01-01
    • 2011-06-30
    • 1970-01-01
    • 2020-03-05
    • 1970-01-01
    相关资源
    最近更新 更多