嘿,所以我试图解析这个HTML,但它没有按预期工作我设法得到标题和链接,但我需要得到大小但它只是因为某些原因没有选择它我尝试了这种方法
请注意我是Simple HTML Dom的新手,我只想猜测如何选择这些。
现在输出的例子
标题>口袋妖怪S19E14 DUBBED 720p HDTV x264-W4F [eztv]
链接> / EP / 148425 /小宠物-s19e14配成-720P-HDTV-X264-W4F /
尺寸>口袋妖怪S19E14 DUBBED 720p HDTV x264-W4F [eztv]
我需要它:
标题>口袋妖怪S19E14 DUBBED 720p HDTV x264-W4F [eztv]
链接> / EP / 148425 /小宠物-s19e14配成-720P-HDTV-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 :(得分:1)
尝试
$e->next_sibling ()
返回元素的下一个兄弟,如果未找到则返回null。
因为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>";
}
}