通过XMLStarlet跳出&号-Bugging& amp; [英] Unescape the ampersand (&) via XMLStarlet - Bugging &

查看:54
本文介绍了通过XMLStarlet跳出&号-Bugging& amp;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个非常烦人但相当简单的任务。根据此指南,我这样写:

This a quite annoying but rather a much simpler task. According to this guide, I wrote this:

#!/bin/bash

content=$(wget "https://example.com/" -O -)
ampersand=$(echo '\&')

xmllint --html --xpath '//*[@id="table"]/tbody' - <<<"$content" 2>/dev/null |
    xmlstarlet sel -t \
        -m "/tbody/tr/td" \
            -o "https://example.com" \
            -v "a//@href" \
            -o "/?A=1" \
            -o "$ampersand" \
            -o "B=2" -n \

我成功地从表中提取了每个链接,并且所有内容都正确地连接在一起,但是,而不是复制<当我在每个链接的末尾收到这个:

I successfully extract each link from the table and everything gets concatenated correctly, however, instead of reproducing the ampersand as & I receive this at the end of each link:

https://example.com/hello-world/?A=1\&amp;B=2

但是实际上,我在寻找类似的东西:

But actually, I was looking for something like:

https://example.com/hello-world/?A=1&B=2

这个想法是使用反斜杠<$来转义字符c $ c> \& ,使其被忽略。最初,我尝试将其直接放入 -o \& \ 代替 -o $ && and 并删除&==(echo'\& ')在这种情况下。结果还是一样。

The idea is to escape the character using a backslash \& so that it gets ignored. Initially, I tried placing it directly into -o "\&" \ instead of -o "$ampersand" \ and removing ampersand=$(echo '\&') in this case scenario. Still the same result.

实质上,通过删除反斜杠,它仍然会输出:

Essentially, by removing the backslash it still outputs:

https://example.com/hello-world/?A=1&amp;B=2

仅删除& 后面的 \

为什么?

我确定这是基本的东西。

I'm sure it is something basic that is missing.

推荐答案

对不起,我无法重现您的结果,但是为什么不进行替换呢?只需通过

Sorry I can't reproduce your result but why don't make substitutions? Just filter your results through

sed 's/\\&amp;/\&/g'

将其添加到管道中。它应替换所有& amp;到&。

add it to your pipe. It should replace all &amp; to &.

这篇关于通过XMLStarlet跳出&号-Bugging&amp; amp;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆