Skip to content Skip to sidebar Skip to footer

Extracting Text From Html Elements With Cheerio

Using cheerio, $ is defined as cheerio object, I am trying to get the text from some elements which have a class forceWordWrap in a html. The following cheerio selectors are return

Solution 1:

Use $("td.forceWordWrap"); selector as Attribute Equals Selector [name=”value”] selects elements that have the specified attribute with a value exactly equal to a certain value.

const text = $("td.forceWordWrap");
const date = text.eq(0).text();
const title = text.eq(1).text();
const description = text.eq(2).text();
console.log(date);
console.log(title);
console.log(description);
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script><formname="his"method="post"action="/a/b.axp"><inputtype="hidden"name="action"value="accept" /><tablewidth="100%"border="0"cellpadding="2"cellspacing="0"><trclass="rowHeading"><tdwidth="14%"><divalign="left"style="white-space:nowrap">
          going home
        </div></td><tdwidth="86%"><divalign="left">
          say bye.
        </div></td></tr><trclass="rowLight"><tdclass="boldBodyText forceWordWrap"><inputtype="hidden"name="king"value="Tut" />the kings
      </td><tdclass="boldBodyText forceWordWrap">
        Reminder – Please see the king.
      </td></tr><trclass="rowLight"><tdstyle="white-space:normal">&nbsp;</td><tdclass="bodyText forceWordWrap">YOu got to do this.
      </td></tr></table>

Post a Comment for "Extracting Text From Html Elements With Cheerio"