0

我对 xidel 很感兴趣,想将它与 namesilo.com API 一起用于更新 DNS 记录。我在构建正确的选择器时遇到了麻烦。比方说,我有以下 xml 响应,我将如何为主机www.mydomain.org选择 record_id ?

<?xml version="1.0"?>
<namesilo>
  <request>
    <operation>dnsListRecords</operation>
    <ip>62.157.5.106</ip>
  </request>
  <reply>
    <code>300</code>
    <detail>success</detail>
    <resource_record>
      <record_id>7e1abd117be5506febe327ab906f67c7</record_id>
      <type>A</type>
      <host>www.mydomain.org</host>
      <value>182.245.2.23</value>
      <ttl>172817</ttl>
      <distance>0</distance>
    </resource_record>
    <resource_record>
      <record_id>7e75694e3da869315b92d386dcbed45b</record_id>
      <type>A</type>
      <host>m.mydomain.org</host>
      <value>21.148.13.45</value>
      <ttl>172817</ttl>
      <distance>0</distance>
    </resource_record>
  </reply>
</namesilo>

我还没有过去xidel --extract //resource_record,真的。//resource_record[host="www.mydomain.org"]/record_id到目前为止,所有类似的尝试都失败了。我猜,通过 grep 和 sed 管道将通过xidel --extract //resource_record | grep www.mydomain.org | sed s/www.mydomain.org.*//来自 namesilo.com 的原始、未经修饰的 XML 响应来工作,但我确信有更好的方法。

4

2 回答 2

1

Does not work: xidel -e //resource_record[host="www.mydomain.org"]/record_id

Generally speaking it's recommended to quote a (extraction) query. That doesn't mean it won't work without quotes:

xidel -s <input> -e //resource_record\[host=\"www.mydomain.org\"\]/record_id
7e1abd117be5506febe327ab906f67c7

It's just that you have to prevent certain characters from being interpreted by Bash's shell by escaping them.

于 2020-07-03T21:53:55.283 回答
0

不工作:xidel -e //resource_record[host="www.mydomain.org"]/record_id

作品:xidel -e '//resource_record[host="www.mydomain.org"]/record_id'

于 2020-07-02T09:37:59.927 回答