Jump to content


Photo

Grabbing Info From Site's HTML DOM Parser

php dom parser html

  • Please log in to reply
1 reply to this topic

#1 Xmodding

Xmodding

    Newbie

  • New Members
  • Pip
  • 1 posts

Posted 05 October 2013 - 02:31 PM

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, 05 October 2013 - 02:43 PM.


#2 Ch0cu3r

Ch0cu3r

    Advanced Member

  • Moderators
  • 2,421 posts

Posted 06 October 2013 - 04:03 AM

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");
}
}
}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com