CSS-package: Extract information from an html document with CSS selectors

Description Details Author(s) Examples

Description

The package provides functions that facilitate extraction of information from an html document by using css selectors instead of xpath queries.

Details

Package: CSS
Type: Package
Version: 1.0
Date: 2013-01-31
License: GPL (>= 2)

The functions of this packages are actually wrapper functions for the package XML. For instance cssApply converts a css path in an xpath query and then invokes xpathSApply.

Author(s)

Francois Guillem <[email protected]>

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
doc <- "<html>
<head></head>
<body>
  <div id='character1' class='character'>
    <span class='name'>Mike</span>
    <span class='level digit'>10</span>
  </div>
  <div id='character2' class='character'>
    <span class='name'>Stan</span>
  </div>
</body>
</html>"

doc <- htmlParse(doc)

# Names of the characters
cssApply(doc, ".character>.name", cssCharacter)

# Name of character1
cssApply(doc, "#character1>.name", cssCharacter)

# Level of characters
cssApply(doc, ".character>.level", cssNumeric)

# character 2 does not have level, we would want to have a NA value instead of nothing
cssApplyInNodeSet(doc, ".character", ".level", cssNumeric)

cuche27/CSS documentation built on May 12, 2017, 1:27 p.m.