An open API service indexing awesome lists of open source software.

https://github.com/hrbrmstr/jericho

:notebook_with_decorative_cover: Extract plain or structured text from HTML content in R
https://github.com/hrbrmstr/jericho

java r r-cyber rstats

Last synced: 8 months ago
JSON representation

:notebook_with_decorative_cover: Extract plain or structured text from HTML content in R

Awesome Lists containing this project

README

          

---
output: rmarkdown::github_document
---

[![Build Status](https://travis-ci.org/hrbrmstr/jericho.svg?branch=master)](https://travis-ci.org/hrbrmstr/jericho)
[![Build status](https://ci.appveyor.com/api/projects/status/nosmgh0b2wthjjf3/branch/master?svg=true)](https://ci.appveyor.com/project/hrbrmstr/jericho/branch/master)
[![codecov](https://codecov.io/gh/hrbrmstr/jericho/branch/master/graph/badge.svg)](https://codecov.io/gh/hrbrmstr/jericho)

`jericho` : Break Down the Walls of 'HTML' Tags into Usable Text

Structured 'HTML' content can be useful when you need to parse data tables or other tagged data from within a document. However, it is also useful to obtain "just the text" from a document free from the walls of tags that surround it. Tools are provied that wrap methods in the 'Jericho HTML Parser' Java library by Martin Jericho . Martin's library is used in many at-scale projects, icluding the 'The Internet Archive'.

As a result of using a Java library, this package requires `rJava`.

The following functions are implemented:

- `html_to_text`: Convert HTML to Text
- `render_html_to_text`: Render HTML to Text

### Installation

If you do use `devtools`, then it *should* pickup the `Remotes:` section in `DESCRIPTION`. Until the package is on CRAN, you might want to also invoke the installation of `jerichojars` as shown below:

```{r eval=FALSE}
install.packages(c("jerichojars", "jericho"), repos = "https://cinc.rud.is/")
```

```{r message=FALSE, warning=FALSE, error=FALSE, include=FALSE}
options(width = 120)
```

### Usage

Let's use [this NASA blog post](https://blogs.nasa.gov/spacestation/2017/09/02/touchdown-expedition-52-back-on-earth/) as an example.

```{r message=FALSE, warning=FALSE, error=FALSE}
library(jericho)

# current verison
packageVersion("jericho")

URL <- "https://blogs.nasa.gov/spacestation/2017/09/02/touchdown-expedition-52-back-on-earth/"

doc <- paste0(readr::read_lines(URL), collapse = "\n")
```

This is pure text extraction:

```{r message=FALSE, warning=FALSE, error=FALSE, eval=FALSE}
html_to_text(doc)
```

This provides a human readable version of the segment content that is modelled on the way Mozilla Thunderbird and other email clients provide an automatic conversion of HTML content to text in their alternative MIME encoding of emails.

```{r message=FALSE, warning=FALSE, error=FALSE, eval=FALSE}
render_html_to_text(doc)
```

You should run each to see and compare the output (GitHub markdown documents aren't the best viewing medium).

### `jericho` Metrics

```{r cloc, echo=FALSE}
cloc::cloc_pkg_md()
```