[英]Get info using PHP Simple HTML DOM
我正在使用 PHP Simple HTML DOM 從站點中抓取數據。 只是想知道如何單獨獲取信息而不是放在一起。
使用這個命令我可以獲得完整的頁面。
$html = file_get_html('http://mp3skull.com/mp3/gangnam_style.html');
foreach($html->find('div#song_html') as $e)
echo $e->innertext . '<br>';
我需要的是分別獲取標題、網址、時間、叮咬。
<div id="song_html" class="show1">
<div class="left">
<!-- info mp3 here -->
320 kbps<br />4:01<br />9.2 mb </div>
<div id="right_song">
<div style="font-size:15px;"><b>Psy - Gangnam style (DJ Pasha Lee & DJ Vitaco remix) - Psy - Gangnam style (DJ Pasha Lee & DJ Vitaco remix) mp3</b></div>
<div style="clear:both;"></div>
<div style="float:left;">
<div style="float:left; height:27px; font-size:13px; padding-top:2px;">
<div style="float:left;"><a href="http://promodj.com/source/3594542/Psy_Gangnam_style_DJ_Pasha_Lee_DJ_Vitaco_remix.mp3" rel="nofollow" target="_blank" style="color:green;">Download</a></div>
<div style="margin-left:8px; float:left; width:27px; text-align:center;"><a href="javascript:void(0)" onclick="showPlayer_new(11683153, '77380784862db5cfb455861b62fdc62690aca7d2', 'psy', 'gangnam+style')" rel="nofollow" id="lk11683153" class="play_now">Play</a></div>
<div style="margin-left:8px; float:left;"><a href="javascript:void(0)" onclick="showEmbed_new(11683153, '77380784862db5cfb455861b62fdc62690aca7d2')" rel="nofollow" id="em11683153" class="embed">Embed</a></div>
<div style="margin-left:8px; float:left;"><a href="http://www.ringtonematcher.com/go/?sid=WDLL&artist=psy&song=gangnam+style" rel="nofollow" target="_blank" style="color:red;" title="Send Psy - Gangnam Style Ringtone to your Cell">Send Ringtone</a></div>
<div style="clear:both;"></div>
</div>
<div id="player11683153" style="float:left; margin-left:10px;" class="player"></div>
</div>
<div style="clear:both;"></div>
</div>
<div style="clear:both;"></div>
</div>
提前致謝。
你可以這樣做
$html = file_get_html('http://mp3skull.com/mp3/gangnam_style.html');
$list = array();
$x = 0 ;
foreach ( $html->find('div#song_html ') as $e ) {
$song = array();
$song['bit'] = preg_replace('!\s+!', ' ',$e->find('div', 0)->plaintext);
$song['title'] = preg_replace('!\s+!', ' ',$e->find('div', 1)->plaintext);
$song['url'] = preg_replace('!\s+!', ' ',$e->find('a', 0)->href);
$list[] = $song;
}
echo "<pre>";
print_r($list);
輸出
Array
(
[0] => Array
(
[bit] => 320 kbps 4:01 9.2 mb
[title] => Psy - Gangnam style (DJ Pasha Lee & DJ Vitaco remix) - Psy - Gangnam style (DJ Pasha Lee & DJ Vitaco remix) mp3 Download Play Embed Send Ringtone
[url] => http://promodj.com/source/3594542/Psy_Gangnam_style_DJ_Pasha_Lee_DJ_Vitaco_remix.mp3
)
[1] => Array
(
[bit] => 320 kbps 4:01 9.2 mb
[title] => Psy - Gangnam style (DJ Pasha Lee & DJ Vitaco remix) - Psy - Gangnam style (DJ Pasha Lee & DJ Vitaco remix) mp3 Download Play Embed Send Ringtone
[url] => http://promodj.com/download/3608444/Psy_Gangnam_style_DJ_Pasha_lee_DJ_Vitaco_remix.mp3
)
[2] => Array
(
[bit] => 128 kbps 4:21 3.98 mb
[title] => Psy - Gangnam Style (Boys Electro Mash-Up) - Psy Gangnam Style Boys Electro Mash Up mp3 Download Play Embed Send Ringtone
[url] => http://promodj.com/download/3614746/Psy_Gangnam_Style_Boys_Electro_Mash_Up.mp3
)
[3] => Array
(
[bit] => 128 kbps 4:21 3.98 mb
[title] => Psy - Gangnam Style (Boys Electro Mash-Up) - Psy Gangnam Style Boys Electro Mash Up mp3 Download Play Embed Send Ringtone
[url] => http://promodj.com/source/3614746/Psy_Gangnam_Style_Boys_Electro_Mash_Up.mp3
)
[4] => Array
(
[bit] => 192 kbps 2:53 3.97 mb
[title] => Jewish style Official parody to PSY GANGNAM STYLE MISSION ARIO REMIX DEMO FUNNY mp3 Download Play Embed Send Ringtone
[url] => http://promodj.com/download/3623591/Jewish_style_Official_parody_to_PSY_GANGNAM_STYLE_MISSION_ARIO_REMIX_DEMO_FUNNY.mp3
)
[5] => Array
(
[bit] => 192 kbps 2:53 3.97 mb
[title] => Jewish style Official parody to PSY GANGNAM STYLE MISSION ARIO REMIX DEMO FUNNY mp3 Download Play Embed Send Ringtone
[url] => http://promodj.com/source/3623591/Jewish_style_Official_parody_to_PSY_GANGNAM_STYLE_MISSION_ARIO_REMIX_DEMO_FUNNY.mp3
)
........ so many more
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.