Jump to content

extract data from website


dingus

Recommended Posts

hi im writeing a script atm and it needs to pull the catagory from youtube videos

 

 

<div>

 

<span class="smallLabel">Category: </span>

<a href="/browse?s=mp&t=t&c=23" class="dg smallText" onclick="_hbLink('VideoCategoryLink','Watch3VideoDetails');">Comedy</a>

</div>

 

 

that block there i have been trying several things but i cant seem to come to a solution how would i extract the word extract the word in read from said page? but it would need to be extracted ignoreing the accual word AND the part in blue i hope there is some one who can help me

Link to comment
https://forums.phpfreaks.com/topic/95897-extract-data-from-website/
Share on other sites

<pre>
<?php

$data = <<<DATA
<div>
	<span class="smallLabel">Category: </span>
	<a href="/browse?s=mp&t=t&c=23" class="dg smallText" onclick="_hbLink('VideoCategoryLink','Watch3VideoDetails');">Comedy</a>
</div>
DATA;

preg_match('/Category.+?<a[^>]+>([^<]+)/s', $data, $matches);
	echo $matches[1];
?>
</pre> 


$subject = <<<EOF
<div>

            <span class="smallLabel">Category: </span>
            <a href="/browse?s=mp&t=t&c=23" class="dg smallText" onclick="_hbLink('VideoCategoryLink','Watch3VideoDetails');">Comedy</a>
</div>
EOF;


if (preg_match_all('%<a href="(/browse?[^"]+)[^>]+>([^<]+)%i', $subject, $matches)) {
print_r($matches);
} else {
# Match attempt failed
}

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.