Status
Not open for further replies.

skinner

Active Member
741
2010
59
5,180
Hi,

I'm trying to extract somethings from pornhub page:

http://www.pornhub.com/video?c=3

I have to use regex to find:

Code:
<a href="http://www.pornhub.com/view_video.php?viewkey=1234567890" target="" title="something" class="title"

I use this:

PHP:
/\<a href=\"http\:\/\/www\.pornhub\.com\/view_video\.php\?viewkey=([0-9]+)\"\s+title=\"([^\"]*)\"\s+class=\"title\"/

but function returned 0.

What is wrong?

Thanks
 
6 comments
try this
Code:
'/view_video.php\?viewkey=([0-9]*).*?target=\"([a-zA-Z0-9]*)?/m'


Thanks..

Sorry, my mistake. I didn't explain well what I need.

this is the source of the page:

Code:
<li class="videoblock videos_6564592" id="6564591" _vkey = "477262185">
	<div class="wrap">
					<a href="http://www.pornhub.com/view_video.php?viewkey=477262185" target="" title="Latina Teen BFF Gets Fucked and a Facial" class="img">
								<img src="http://cdn1.static.pornhub.phncdn.com/images/blank.gif" alt="Latina Teen BFF Gets Fucked and a Facial" data-smallthumb="http://thumb1.cdn1a.image.pornhub.phncdn.com/videos/201210/22/6564591/160x120/11.jpg?cache=525779" data-mediumthumb="http://thumb1.cdn1a.image.pornhub.phncdn.com/videos/201210/22/6564591/240x180/11.jpg?cache=525779" class="rotating" id="v6564591" onmouseover="startThumbChange(6564591, 'v6564591', 16, 'http://thumb1.cdn1a.image.pornhub.phncdn.com/videos/201210/22/6564591/160x120/');" onmouseout="endThumbChange('v6564591');" />
					</a>
		
		<div class="add-to-playlist-icon display-none">
			<button type="button" data-title="Add to a Playlist" class="tooltipTrig open-playlist-link playlist-trigger" onclick="return false;" data-rel="477262185" >+</button>
		</div>

		<div class="thumbnail-info-wrapper">
			<span class="title" style="display: block;">
							<a href="http://www.pornhub.com/view_video.php?viewkey=477262185" target="" title="Latina Teen BFF Gets Fucked and a Facial" class="title">Latina Teen BFF Gets Fucked and a Facial</a>
						</span>
			<div class="rating-container up">
				<div class="value">100%</div>
				<div class="main-sprite icon"></div>
			</div>
			<var class="duration">10:00</var>
			<span class="views"><var>1,973</var> views</span>
			<var class="added">21 minutes ago</var>
		</div>
					</div>
</li>

<li class="videoblock videos_7787082" id="7787081" _vkey = "1960768929">
	<div class="wrap">
					<a href="http://www.pornhub.com/view_video.php?viewkey=1960768929" target="" title="school girl 0671911_clip5.wmv" class="img">
								<img src="http://cdn1.static.pornhub.phncdn.com/images/blank.gif" alt="school girl 0671911_clip5.wmv" data-smallthumb="http://thumb1.cdn1a.image.pornhub.phncdn.com/videos/201212/03/7787081/160x120/16.jpg?cache=" data-mediumthumb="http://thumb1.cdn1a.image.pornhub.phncdn.com/videos/201212/03/7787081/240x180/16.jpg?cache=" class="rotating" id="v7787081" onmouseover="startThumbChange(7787081, 'v7787081', 16, 'http://thumb1.cdn1a.image.pornhub.phncdn.com/videos/201212/03/7787081/160x120/');" onmouseout="endThumbChange('v7787081');" />
					</a>
		
		<div class="add-to-playlist-icon display-none">
			<button type="button" data-title="Add to a Playlist" class="tooltipTrig open-playlist-link playlist-trigger" onclick="return false;" data-rel="1960768929" >+</button>
		</div>

		<div class="thumbnail-info-wrapper">
			<span class="title" style="display: block;">
							<a href="http://www.pornhub.com/view_video.php?viewkey=1960768929" target="" title="school girl 0671911_clip5.wmv" class="title">school girl 0671911_clip5.wmv</a>
						</span>
			<div class="rating-container up">
				<div class="value">71%</div>
				<div class="main-sprite icon"></div>
			</div>
			<var class="duration">29:22</var>
			<span class="views"><var>3,152</var> views</span>
			<var class="added">36 minutes ago</var>
		</div>
					</div>
</li>

<li class="videoblock videos_5136183" id="5136182" _vkey = "1979434273">
	<div class="wrap">
					<a href="http://www.pornhub.com/view_video.php?viewkey=1979434273" target="" title="Girl Fingers Her Pussy Close To Webcam" class="img">
								<img src="http://cdn1.static.pornhub.phncdn.com/images/blank.gif" alt="Girl Fingers Her Pussy Close To Webcam" data-smallthumb="http://cdn3.image.pornhub.phncdn.com/thumbs/005/136/182/small.jpg?cache=7198790" data-mediumthumb="http://cdn3.image.pornhub.phncdn.com/thumbs/005/136/182/medium.jpg?cache=7198790" class="rotating" id="v5136182" onmouseover="startThumbChange(5136182, 'v5136182', 16, 'http://cdn3.image.pornhub.phncdn.com/thumbs/005/136/182/');" onmouseout="endThumbChange('v5136182');" />
					</a>
		
		<div class="add-to-playlist-icon display-none">
			<button type="button" data-title="Add to a Playlist" class="tooltipTrig open-playlist-link playlist-trigger" onclick="return false;" data-rel="1979434273" >+</button>
		</div>

		<div class="thumbnail-info-wrapper">
			<span class="title" style="display: block;">
							<a href="http://www.pornhub.com/view_video.php?viewkey=1979434273" target="" title="Girl Fingers Her Pussy Close To Webcam" class="title">Girl Fingers Her Pussy Close To Webcam</a>
						</span>
			<div class="rating-container up">
				<div class="value">95%</div>
				<div class="main-sprite icon"></div>
			</div>
			<var class="duration">11:10</var>
			<span class="views"><var>4,397</var> views</span>
			<var class="added">51 minutes ago</var>
		</div>
					</div>
</li>

<li class="videoblock videos_8119612" id="8119611" _vkey = "897683572">
	<div class="wrap">
					<a href="http://www.pornhub.com/view_video.php?viewkey=897683572" target="" title="3 Way Fuckers - Scene 2" class="img">
								<img src="http://cdn1.static.pornhub.phncdn.com/images/blank.gif" alt="3 Way Fuckers - Scene 2" data-smallthumb="http://thumb1.cdn1a.image.pornhub.phncdn.com/videos/201212/13/8119611/160x120/3.jpg?cache=" data-mediumthumb="http://thumb1.cdn1a.image.pornhub.phncdn.com/videos/201212/13/8119611/240x180/3.jpg?cache=" class="rotating" id="v8119611" onmouseover="startThumbChange(8119611, 'v8119611', 16, 'http://thumb1.cdn1a.image.pornhub.phncdn.com/videos/201212/13/8119611/160x120/');" onmouseout="endThumbChange('v8119611');" />
					</a>
		
		<div class="add-to-playlist-icon display-none">
			<button type="button" data-title="Add to a Playlist" class="tooltipTrig open-playlist-link playlist-trigger" onclick="return false;" data-rel="897683572" >+</button>
		</div>

		<div class="thumbnail-info-wrapper">
			<span class="title" style="display: block;">
							<a href="http://www.pornhub.com/view_video.php?viewkey=897683572" target="" title="3 Way Fuckers - Scene 2" class="title">3 Way Fuckers - Scene 2</a>
						</span>
			<div class="rating-container up">
				<div class="value">93%</div>
				<div class="main-sprite icon"></div>
			</div>
			<var class="duration">32:41</var>
			<span class="views"><var>9,507</var> views</span>
			<var class="added">1 hour ago</var>
		</div>
					</div>
</li>

What I need is extract:
  1. Title;
  2. ClipID;
  3. SmallThumb;
  4. Duration.

I use that regex:

PHP:
preg_match_all('#<a href="http://www.pornhub.com/view_video\.php\?viewkey=([0-9]+)".+?title="(.+?)".+?class="title".*?<img src="(.+?)".+?id="v(.+?)"#si', $html, $clips, PREG_SET_ORDER);

and I obtain:

PHP:
$linkVideo = $val[0]; // Source with link video
$clipid    = $val[1]; // ClipID like 1979434273
$title     = $val[2]; // Title of video

I use $val[0] to extract SmallThumb:

PHP:
preg_match_all('#".*?<img src="(.+?)".+?data-smallthumb="(.+?)"#si', $val[0], $thumb, PREG_SET_ORDER);

and duration of video:

PHP:
preg_match("/var class=\"duration\"\>.*([0-9\:]+)\<\/var\>/msU", $val[0], $duration)

But the problem is that I get link of video 1 and thumb of video 2, and link of video 2 with thumb of video 3 and so on..

I need to print out link of video 1 with its associated thumb, and not thumb of the next video.

Hope you understand what I need.

Thanks
 
TRy this for all of them
Code:
'%(?si)<li class="videoblock.*?view_video.php\?viewkey=([0-9]*).*?title=\"(.*?)".*?smallthumb="(.*?)".*?class="duration">(.*?)<.*?</li>%m'
 
Status
Not open for further replies.
Back
Top