XPath within R using XML package

后端 未结 2 1604
孤独总比滥情好
孤独总比滥情好 2020-12-28 10:33

I am new to XPath, but I can see how powerful it is. I am looking at the source code of this link and simply want to extract the contents and username from the following tw

相关标签:
2条回答
  • 2020-12-28 11:10

    Use:

    /*/head/meta[@name='description']/@content
    

    This still selects an attribute node, but probably there is an easy way in your PL to get the string value of the attribute.

    To get just the string value, use:

    string(/*/head/meta[@name='description']/@content)
    

    Do note: Using the // abbreviation may result in very slow evaluation of the XPath expression, because it may cause a linear traversal of a whole (sub)tree.

    Always avoid using // if the structure of the XML document is statically known .

    0 讨论(0)
  • 2020-12-28 11:15

    You're close. This should do it.

    //head/meta[@name=\"description\"]/@content
    

    The brackets are constraining the choice of meta tags, but you still have to specify the attribute you want.

    0 讨论(0)
提交回复
热议问题