【R】rvestでhtml_textのふるまい
2021年7月9日
こちらのページに、html_textとhtml_text2のふるまいの違いが解説されていたので、確認してみた。
library(rvest)
html <- minimal_html(
"<h1>section 1</h1>
<p>This is a paragraph.
This another sentence.<br>new line<br>new line2"
)
html %>% html_element("p") %>% html_text() %>% writeLines()
html %>% html_element("p") %>% html_text2() %>% writeLines()
This is a paragraph.
This another sentence.new linenew line2
This is a paragraph. This another sentence.
new line
new line2
なるぼど、こういう感じに違うんですね。html_text2ではちゃんと改行を認識してその通りに表示してくれます。