2016-05-22 2 views
0

Эй, я пытаюсь разобрать этот html, но он не работает, как и ожидалось. Мне удалось получить название и ссылку, но мне нужно получить размер, но его просто не выбирая по какой-то причине я попробовал этот методSimple HTML Dom не работает как ожидалось

Обратите внимание, что я новичок в Simple HTML Dom, и я просто угадываю, как их выбрать.

Пример выводит Теперь

Название> Покемон S19E14 Дублированный 720p HDTV x264-W4F [EZTV]

Ссылка>/EP/148425/покемон-s19e14-дублирован-720p-ТВЧ-x264-W4F/

Размер> Pokemon S19E14 Дублированный 720p HDTV x264-W4F [EZTV]

мне это нужно:

Название> Pokemon S19E14 720p HDTV Дублированный x264-W4F [EZTV]

Link>/ер/148425/покемон-s19e14-дублированный-720p-ТВЧ-x264-W4F/

Размер> 523,10 MB

$html = str_get_html("<td align=\"center\" class=\"forum_thread_post\"> 
    <a href=\"pokemonlink\" rel=\"nofollow\" class=\"download_1\" title=\"Pokemon S19E14 DUBBED HDTV x264-W4F Torrent: Download Mirror #1\"></a> 
    </td> 
    <td align=\"center\" class=\"forum_thread_post\">175.32 MB</td> 
    <td align=\"center\" class=\"forum_thread_post\">4h 23m</td> 
    <td align=\"center\" class=\"forum_thread_post_end\"><a href=\"/forum/discuss/148426/\" rel=\"nofollow\" title=\"Discuss about Pokemon S19E14 DUBBED HDTV x264-W4F [eztv]:\"><img src=\"/ezimg/s/1/3/chat_empty.png\" border=\"0\" width=\"16\" height=\"16\" alt=\"Discuss\" title=\"Discuss about this show\"/></a></td> 
    </tr> 
    <tr name=\"hover\" class=\"forum_header_border\"> 
    <td width=\"35\" class=\"forum_thread_post\"><a href=\"/shows/1253/pokemon/\" title=\"Pokémon Torrent\"><img src=\"/ezimg/s/1/3/show_info.png\" border=\"0\" alt=\"Show\" title=\"Show Description about Pokémon\"></a><a href=\"http://www.tvmaze.com/episodes/762956/pokemon-the-series-xy-19x14-an-explosive-operation\" target=\"_blank\" title=\"More info about Pokemon S19E14 DUBBED 720p HDTV x264-W4F [eztv] at tvmaze.com\" onclick=\"trackOutboundLink('http://www.tvmaze.com/episodes/762956/pokemon-the-series-xy-19x14-an-explosive-operation'); return false;\"><img src=\"/images/tvmaze-16x16.png\" width=\"16\" height=\"16\" border=\"0\" alt=\"TVmaze\"/></a></td> 
    <td class=\"forum_thread_post\"> 
    <a href=\"/ep/148425/pokemon-s19e14-dubbed-720p-hdtv-x264-w4f/\" title=\"Pokemon S19E14 DUBBED 720p HDTV x264-W4F [eztv] (523.10 MB)\" alt=\"Pokemon S19E14 DUBBED 720p HDTV x264-W4F [eztv] (523.10 MB)\" class=\"epinfo\">Pokemon S19E14 DUBBED 720p HDTV x264-W4F [eztv]</a> 
    </td> 
    <td align=\"center\" class=\"forum_thread_post\"> 
    <a href=\"pokemonlink\" rel=\"nofollow\" class=\"download_1\" title=\"Pokemon S19E14 DUBBED 720p HDTV x264-W4F Torrent: Download Mirror #1\"></a> 
    </td> 
    <td align=\"center\" class=\"forum_thread_post\">523.10 MB</td> 
    <td align=\"center\" class=\"forum_thread_post\">4h 23m</td> 
    <td align=\"center\" class=\"forum_thread_post_end\"><a href=\"/forum/discuss/148425/\" rel=\"nofollow\" title=\"Discuss about Pokemon S19E14 DUBBED 720p HDTV x264-W4F [eztv]:\"><img src=\"/ezimg/s/1/3/chat_empty.png\" border=\"0\" width=\"16\" height=\"16\" alt=\"Discuss\" title=\"Discuss about this show\"/></a></td> 
    </tr>"); 

$tdTorrents = $html->find("td[class=forum_thread_post]"); 
foreach ($tdTorrents as $torrent) { 
    if(($torrent->find("a[class=epinfo]", 0))) { 
     $title = $torrent->find("a[class=epinfo]", 0)->innertext; 
     $link = $torrent->find("a[class=epinfo]", 0)->href; 
     if (strpos($torrent->innertext, "MB") !== false || strpos($torrent->innertext, "KB") !== false || strpos($torrent->innertext, "GB")!== false) { 
      $Size = $torrent->innertext; 
      print "<br>Title > ".$title."</br> 
       <br>Link > ".$link."</br> 
       <br>Size > ".$Size."</br>"; 
     } 
    } 

} 

Любая помощь признательн благодарит HTML я использую там внизу.

<td align="center" class="forum_thread_post"> 
<a href="pokemonlink" rel="nofollow" class="download_1" title="Pokemon S19E14 DUBBED HDTV x264-W4F Torrent: Download Mirror #1"></a> 
</td> 
<td align="center" class="forum_thread_post">175.32 MB</td> 
<td align="center" class="forum_thread_post">4h 23m</td> 
<td align="center" class="forum_thread_post_end"><a href="/forum/discuss/148426/" rel="nofollow" title="Discuss about Pokemon S19E14 DUBBED HDTV x264-W4F [eztv]:"><img src="/ezimg/s/1/3/chat_empty.png" border="0" width="16" height="16" alt="Discuss" title="Discuss about this show"/></a></td> 
</tr> 
<tr name="hover" class="forum_header_border"> 
<td width="35" class="forum_thread_post"><a href="/shows/1253/pokemon/" title="Pokémon Torrent"><img src="/ezimg/s/1/3/show_info.png" border="0" alt="Show" title="Show Description about Pokémon"></a><a href="http://www.tvmaze.com/episodes/762956/pokemon-the-series-xy-19x14-an-explosive-operation" target="_blank" title="More info about Pokemon S19E14 DUBBED 720p HDTV x264-W4F [eztv] at tvmaze.com" onclick="trackOutboundLink('http://www.tvmaze.com/episodes/762956/pokemon-the-series-xy-19x14-an-explosive-operation'); return false;"><img src="/images/tvmaze-16x16.png" width="16" height="16" border="0" alt="TVmaze"/></a></td> 
<td class="forum_thread_post"> 
<a href="/ep/148425/pokemon-s19e14-dubbed-720p-hdtv-x264-w4f/" title="Pokemon S19E14 DUBBED 720p HDTV x264-W4F [eztv] (523.10 MB)" alt="Pokemon S19E14 DUBBED 720p HDTV x264-W4F [eztv] (523.10 MB)" class="epinfo">Pokemon S19E14 DUBBED 720p HDTV x264-W4F [eztv]</a> 
</td> 
<td align="center" class="forum_thread_post"> 
<a href="pokemonlink" rel="nofollow" class="download_1" title="Pokemon S19E14 DUBBED 720p HDTV x264-W4F Torrent: Download Mirror #1"></a> 
</td> 
<td align="center" class="forum_thread_post">523.10 MB</td> 
<td align="center" class="forum_thread_post">4h 23m</td> 
<td align="center" class="forum_thread_post_end"><a href="/forum/discuss/148425/" rel="nofollow" title="Discuss about Pokemon S19E14 DUBBED 720p HDTV x264-W4F [eztv]:"><img src="/ezimg/s/1/3/chat_empty.png" border="0" width="16" height="16" alt="Discuss" title="Discuss about this show"/></a></td> 
</tr> 
+0

'Size' является частью' атрибута alt' из 'a.classinfo' , –

+0

523.10 MB<< Мне нужно получить это без заголовка. – Punxor

ответ

1

Попробуйте

$e->next_sibling() Возвращает следующий родственный элемента, или ноль, если не найден.

Поскольку td с размером является следующим сестринским следующим родственным td с a.epinfo, вы можете попробовать:

if(($torrent->find("a[class=epinfo]", 0))) { 
    $title = $torrent->find("a[class=epinfo]", 0)->innertext; 
    $link = $torrent->find("a[class=epinfo]", 0)->href; 
    if (strpos($torrent->innertext, "MB") !== false || strpos($torrent->innertext, "KB") !== false || strpos($torrent->innertext, "GB")!== false) { 

     $Size = ''; 
     // next sibling of next sibling   
     $size_el = $torrent->next_sibling()->next_sibling(); 
     // make sure it's not NULL 
     if ($size_el) { 
      $Size = $size_el->innertext; 
     } 

     print "<br>Title > ".$title."</br> 
      <br>Link > ".$link."</br> 
      <br>Size > ".$Size."</br>"; 
    } 
} 
+0

Его не работает для меня, размер пуст. – Punxor

+0

Также неудачный вывод пуст – Punxor

+0

Обновлено. 'td' с размером является следующим братом следующего брата текущего' td'. –

Смежные вопросы