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
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> 

Link to comment
Share on other sites


$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
}

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.