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.

Edited by Xmodding
Link to comment
Share on other sites

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");
}
}
}
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.