Things about the “Simple HTML DOM Parser”

Here’s the webpage that has some very useful information about the “simple_html_dom.php”: http://simplehtmldom.sourceforge.net/

How to get the “content” attribute from meta tag using simple_html_dom.php:


function get_videos_from_landing_pages( $landingPage ) {
$vidURL = "";

// Get the page that contains the instructors bio in it.
$html = file_get_html( $landingPage );

$landingpageHTML = plugin_dir_path( __FILE__ ) . "landing-page.txt";
file_put_contents( $landingpageHTML, $html, FILE_APPEND );

// From the page obtain the paragraph tags inside the div element that contains the instructor's bio.
if( !empty( $html ) ) {

$vidURL = $html->find( 'meta[property=og:video]', 0 );

$vidURL = $vidURL->content;
// For debugging, create a file path and a file name
$youtubeSource = plugin_dir_path( __FILE__ ) . "source-description.txt";

// For debugging, write the contents of the string to a file to see what value is being obtained.
file_put_contents( $youtubeSource, $vidURL . PHP_EOL, FILE_APPEND );
}
return $vidURL;
}


How to get the value stored inside the p tag of a div inside the class “js-simple-collapse-inner”:

function getInstructorBio( $courseInstructorBioURL ) {

// Get the page that contains the instructors bio in it.
$html = file_get_html('https://www.udemy.com' . $courseInstructorBioURL);

// From the page obtain the paragraph tags inside the div element that contains the instructor's bio.
$description = $html->find('div.js-simple-collapse-inner p');

// The data obtained is in the form of an array. It needs to be changed into a string.
$strDescription = implode( " ", $description );

// For debugging, create a file path and a file name
//$instructorDescription = plugin_dir_path( __FILE__ ) . "instructor-description.txt";
// For debugging, write the contents of the string to a file to see what value is being obtained.
//file_put_contents( $instructorDescription, $courseInstructorBioURL . " - ", FILE_APPEND );

return $strDescription;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s