Since cognitive processes are challenging for Python programmers, this is pretty much what the (not great idiom in) the appropriately-acronym'd BS 4 text => get_text() does (https://github.com/wention/BeautifulSoup4/blob/03a2b3a9d1fc5877212d9d382a512663f24c887d/bs4/element.py#L846-L854). There are FAR BETTER WAYS to get text than this, but I would not expect Python things to grok that.
Last active
October 17, 2018 16:15
-
-
Save hrbrmstr/fb0d24bf6c51d2c3e686ae277c9d22d5 to your computer and use it in GitHub Desktop.
really pathetic child text tag extraction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rvest) | |
read_html(paste0(readLines(textConnection("<html> | |
<body> | |
<p> Simple paragraph </p> | |
<p> Another properly formatted simple paragraph </p> | |
<div> | |
<p> Another properly formatted simple paragraph in a div element </p> | |
</div> | |
</body> | |
</html>")), collapse="\n")) -> doc | |
map_chr(html_children(doc), html_text) | |
## [1] "\n Simple paragraph \n Another properly formatted simple paragraph \n\n Another properly formatted simple paragraph in a div element \n\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment