Jump to content

Grabbing Info From Site's HTML DOM Parser


Xmodding

Recommended Posts

Hi can someone help me out as i'm new to php.

I have a grabber built in to my script that gets info from other sites for example.

This part is from the site that my grabber gets the info from.

<div class="txt-block">
<h4 class="inline">Runtime:</h4> 
<time itemprop="duration" datetime="PT103M">103 min</time>
</div>

And this is how my grabber gets this info from the site.

$times = $dom->getElementsByTagName('time');
for($i=0; $i<$times->length; $i++){
$itemprop = $times->item($i)->getAttribute("itemprop");
if ($itemprop == "duration"){
if ($times->item($i)->textContent!='-'){
$res['duration'] = $times->item($i)->textContent;
}
}
}

Now what i'm stuck on is what would the code be to get the date published from the site.

<span class="nobr">
<a href="/title/tt0099785/releaseinfo?ref_=tt_ov_inf " title="See all release dates"> 16 November 1990
<meta itemprop="datePublished" content="1990-11-16">
(USA)
</a> 
</span>

Would it be something like this.

$meta = $dom->getElementsByTagName('meta');
for($i=0; $i<$meta->length; $i++){
$itemprop = $meta->item($i)->getAttribute("itemprop");
if ($itemprop == "datePublished"){
if ($meta->item($i)->textContent!='-'){
$res['datePublished'] = $meta->item($i)->textContent;
}
}
}

Could someone please help as i don't have a clue about writing php.

Not, sure but you need to get the date from the content attribute so maybe

$meta = $dom->getElementsByTagName('meta');
for($i=0; $i<$meta->length; $i++){
$itemprop = $meta->item($i)->getAttribute("itemprop");
if ($itemprop == "datePublished"){
   $res['datePublished'] = $meta->item($i)->getAttribute("content");
}
}
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.