Rollo99
Rollo99

Reputation: 1613

How to paste many "nodes" of text into one single text?

I have webscraped this https://www.ecb.europa.eu/press/pressconf/2019/html/ecb.is190912~658eb51d68.en.html. The problem is that the text is divided into as many paragraphs as SelectorGadget selected. Instead, I would like it to be one single text.

I have the following code that you can replicate to better understand the problem:

url_ecb_190124 <- "https://www.ecb.europa.eu/press/pressconf/2019/html/ecb.is190124~cd3821f8f5.en.html"

    ecb_190124 <- read_html(url_ecb_190124)

statements1 <- html_text(html_nodes(ecb_190124, ".ecb-pressCategory~ p+ p"))

Unfortunately, "statements1" takes [86] paraghraps (86 obs.), whereas I just want it to be one single observation. I tried without results all the commands I am ware of ("paste", "rbind", etc.).

Does anyone know how I can sort it out?

Thanks a lot!

Upvotes: 3

Views: 89

Answers (2)

John Carty
John Carty

Reputation: 252

Just use paste

paste(statements1, collapse = "")

when you add the collapse parameter it combines all elements in a vector and separates them with what you put in the quotes.

Upvotes: 1

akrun
akrun

Reputation: 887148

We can use toString

toString(statements1)

Upvotes: 0

Related Questions