selectr: Translate CSS Selectors to XPath Expressions
- CRAN: http://cran.r-project.org/web/packages/selectr/index.html
- GitHub: https://github.com/sjp/selectr
> library(selectr)
バージョン: 0.3.0
関数名 | 概略 |
---|---|
css_to_xpath |
Translate a CSS selector to an equivalent XPath expression. |
querySelectorAll |
Find nodes that match a group of CSS selectors in an XML tree. |
css_to_xpath
Arguments
- selector
- prefix
- translator
> css_to_xpath(".testclass")
[1] "descendant-or-self::*[@class and contains(concat(' ', normalize-space(@class), ' '), ' testclass ')]"
> css_to_xpath("#testid", prefix = "")
[1] "*[@id = 'testid']"
> css_to_xpath("#testid .testclass")
[1] "descendant-or-self::*[@id = 'testid']/descendant::*[@class and contains(concat(' ', normalize-space(@class), ' '), ' testclass ')]"
querySelectorAll
Arguments
- doc
- selector
- ns
- prefix
- ...
> svgdoc <- xml2::read_xml(system.file("demos/svg-mathml.svg",
+ package = "selectr"))
>
> querySelectorNS(svgdoc, "svg|script",
+ c(svg = "http://www.w3.org/2000/svg"))
{xml_node}
<script type="application/ecmascript" href="test2.svg.coords.js">
> querySelectorAllNS(svgdoc, "svg|script",
+ c(svg = "http://www.w3.org/2000/svg"))
{xml_nodeset (2)}
[1] <script type="application/ecmascript" xlink:href="test2.svg.coords.j ...
[2] <script type="application/ecmascript" xlink:href="test2.svg.convert. ...
> exdoc <- xml2::read_xml('<a><b class="aclass"/><c id="anid"/></a>')
> querySelector(exdoc, "#anid")
{xml_node}
<c id="anid">
> querySelector(exdoc, ".aclass")
{xml_node}
<b class="aclass">
> querySelector(exdoc, "b, c")
{xml_node}
<b class="aclass">
> querySelectorAll(exdoc, "b, c")
{xml_nodeset (2)}
[1] <b class="aclass"/>
[2] <c id="anid"/>
> querySelectorAll(exdoc, "b")
{xml_nodeset (1)}
[1] <b class="aclass"/>
> querySelector(exdoc, "d")
NULL
> querySelectorAll(exdoc, "d")
{xml_nodeset (0)}
> library(rvest)
> x <- read_html("https://github.com/sjp/selectr")
> querySelector(x, ".anchor")
{xml_node}
<a id="user-content-selectr" class="anchor" href="#selectr" aria-hidden="true">
[1] <svg aria-hidden="true" class="octicon octicon-link" height="16" ver ...