4
$\begingroup$

I'd like to import plaintext found within paragraph blocks nested anywhere inside certain div's. Here's a page to try it on:

Import @ "https://trailhead.salesforce.com/content/learn/modules/european-union-privacy-law-basics/get-to-know-eu-privacy-law?trail_id=learn-privacy-and-data-protection-law"

I'm trying to extract strings text1, text2, etc. from <p> blocks whenever nested inside any <div>'s of class "unit-content":

... <div class="unit-content"> ... <p> text1 </p> ... <p> text2 </p> ... </div> ...

Is there an easier way than using the nasty 'XML' functions?

$\endgroup$
4
$\begingroup$

You can use jsoupLink for this:

Needs["jsoupLink`"]

html = Import[
   "https://trailhead.salesforce.com/content/learn/modules/european-union-privacy-law-basics/get-to-know-eu-privacy-law?trail_id=learn-privacy-and-data-protection-law",
   "HTMLDOM"
   ];

texts = #["AllText"] & /@ html["Select", ".unit-content p"];
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.