{"id":3888,"date":"2016-04-25T01:53:38","date_gmt":"2016-04-25T01:53:38","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=3888"},"modified":"2016-04-25T01:53:38","modified_gmt":"2016-04-25T01:53:38","slug":"nodejs-get-text-within-div","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/nodejs-get-text-within-div\/","title":{"rendered":"Node: get all text within a div"},"content":{"rendered":"<p>There are a lot of examples that get you parts of the text on a page, but most of them don&#8217;t seem to be able to get nested text.<\/p>\n<p>The easiest way to do this is with jsDom, which is also the heaviest one:<\/p>\n<pre lang=\"javascript\">\nlet jsdom = require('jsdom');\n\nlet file = 'D:\/projects\/image-annotation\/data\/talks\/pages\/talk200.html';\njsdom.env(\n  file,\n  [\"http:\/\/code.jquery.com\/jquery.js\"],\n  (err, window) => {\n    console.log(\n      window.$(\".transcript-text\").text()\n    );\n  }\n);\n<\/pre>\n<p>This will get you the entire text contents within a section of the page, which is ideal if you&#8217;re doing scraping.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Example of pulling text off a page in Node<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4],"tags":[302,495],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/3888"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=3888"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/3888\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=3888"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=3888"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=3888"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}