gpt4 book ai didi

php - 如何获取标签后的文字

转载 作者:行者123 更新时间:2023-12-05 07:56:49 26 4
gpt4 key购买 nike

我正在使用简单的 HTML DOM 解析器 php

我不明白如何在标签后获取文本,例如(<b></b> Text)。

请看下图。我正在访问这个网站并得到这个 HTML

Image Link

我想从上面的图像细节中创建这样的 array():

array(

'release_year'=> 2009,
'genre' => 'Drama,Fantasy,Horror',
'description' => 'etc etc etc',
'imdb' => 'link of imdb',
'total_episode'=> '28 episode',
'latest_episode_title'=> 'title',
'latest_episode_link' => 'link',
'latest_episode_with_link_title'=> 'title',
'latest_episode_with_link_link' => 'link',
);

我成功地在标签 <b></b> 下获取文本但我不知道如何在 <b> 之后获取文本HTML 中显示的标签。请查看它以及我的 PHP 代码和结果,请解决我的问题。非常感谢您。

这是上图的HTML:

<div class="show-summary">
<table border="0" style="padding:3px">
<tbody>
<tr>
<td style="padding:3px">
<a href="/serie/the_vampire_diaries">
<img src="http://static1.watchseries.ag/90/1/The_Vampire_Diaries-18597.JPEG" alt="Watch Series - The Vampire Diaries" title="Watch Series - The Vampire Diaries" height="120px" width="85px">
</a>
</td>

<td valign="top" style="padding:3px">
<p>
<b>Release Year: </b>
2009<br>

<b>Genre: <a href="/genres/Drama">Drama</a>, <a href="/genres/Fantasy">Fantasy</a>, <a href="/genres/Horror">Horror</a></b>

<br>

<b>External Links: </b>
<a href="http://www.imdb.com/title/tt1405406/" target="_blank">IMDB</a>

<br>

<b>No. of episodes: </b>
128 episodes <br>

<b>Latest Episode: </b>
<a title="Watch The Vampire Diaries Latest Episode (The Vampire Diaries Season 6 Episode 16)" href="/episode/the_vampire_diaries_s6_e16.html">Season 6 Episode 16 The Downward Spiral (26/02/2015)</a>

<br>

<b>Latest Episode With Links: </b>
<a title="Watch The Vampire Diaries Latest Episode (The Vampire Diaries Season 6 Episode 11)" href="/episode/the_vampire_diaries_s6_e11.html">Season 6 Episode 11 Woke Up With a Monster (22/01/2015)</a>

<br>

</p>

<div style="float: left; height: 30px; overflow: hidden; width: 100px;">
<div class="fb-like fb_iframe_widget" data-href="http://watchseries.ag/serie/the_vampire_diaries" data-send="false" data-layout="button_count" data-show-faces="false" fb-xfbml-state="rendered" fb-iframe-plugin-query="app_id=434603673340441&amp;href=http%3A%2F%2Fwatchseries.ag%2Fserie%2Fthe_vampire_diaries&amp;layout=button_count&amp;locale=en_US&amp;sdk=joey&amp;send=false&amp;show_faces=false">
<span style="vertical-align: bottom; width: 79px; height: 20px;">
<iframe name="fbc5b3f58" width="1000px" height="1000px" frameborder="0" allowtransparency="true" scrolling="no" title="fb:like Facebook Social Plugin" src="http://www.facebook.com/plugins/like.php?app_id=434603673340441&amp;channel=http%3A%2F%2Fstatic.ak.facebook.com%2Fconnect%2Fxd_arbiter%2F7r8gQb8MIqE.js%3Fversion%3D41%23cb%3Df314058a5%26domain%3Dwatchseries.ag%26origin%3Dhttp%253A%252F%252Fwatchseries.ag%252Ff5fff1c%26relation%3Dparent.parent&amp;href=http%3A%2F%2Fwatchseries.ag%2Fserie%2Fthe_vampire_diaries&amp;layout=button_count&amp;locale=en_US&amp;sdk=joey&amp;send=false&amp;show_faces=false" style="border: none; visibility: visible; width: 79px; height: 20px;" class="" __idm_id__="824321"></iframe>
</span>
</div>
</div>
<iframe id="twitter-widget-1" scrolling="no" frameborder="0" allowtransparency="true" src="http://platform.twitter.com/widgets/tweet_button.b68aed79dd9ad79554bcd8c9141c94c8.en.html#_=1422079075304&amp;count=horizontal&amp;dnt=false&amp;id=twitter-widget-1&amp;lang=en&amp;original_referer=http%3A%2F%2Fwatchseries.ag%2Fserie%2Fthe_vampire_diaries&amp;size=m&amp;text=Watch%20The%20Vampire%20Diaries%20Serie%20Online%20-%20Watch%20Series&amp;url=http%3A%2F%2Fwatchseries.ag%2Fserie%2Fthe_vampire_diaries" class="twitter-share-button twitter-tweet-button twitter-share-button twitter-count-horizontal" title="Twitter Tweet Button" data-twttr-rendered="true" style="width: 107px; height: 20px;"></iframe>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>

<br clear="all">

<b>Description :</b>
The vampire brothers Damon and Stefan Salvatore, eternal adolescents, having been leading 'normal' lives, hiding their bloodthirsty condition, for centuries, moving on before their non-aging is noticed.
<span id="plot_mored"> They are back in the Virginia town where they became vampires. Stefan is noble, denying himself blood to avoid killing, and tries to control his evil brother Damon. Stefan falls in love with schoolgirl Elena, whose best friend is a witch, like her grandma.</span>
<a onclick="return showMoreContent('plot_mored');" class="small dark" href="#" id="more" style="display: none;">[+]more</a>

<br>

<p></p>
</td>
</tr>
</tbody>
</table>
</div>

这是我的 PHP 代码:

$html = new simple_html_dom();

$html->load_file("LINK");

foreach($html->find('div.show-summary table tbody tr') as $rowz){

foreach($rowz->find('p') as $p){

foreach($p->find('b') as $b){

echo $b->innertext.'<br/>';
}

}
}

通过运行上面的代码,我得到以下结果:

Release Year:

Genre: Drama, Fantasy, Horror

External Links:

No. of episodes:

Latest Episode:

Latest Episode With Links:

Description :

我想创建一个包含上述图像细节的数组。

最佳答案

如果文件更改很多,这可能不是您想要的,但是如果您按照以下方式做了什么

$html = new simple_html_dom();

$html->load_file("LINK");

foreach($html->find('div.show-summary table tbody tr') as $rowz){

foreach($rowz->find('p') as $p){

$matches = explode('<br>',$p->innertext);
foreach ($matches as $entry) {
preg_match('/<b>(.*)</b>(.*)/i', $entry, $stuff);
echo "{$stuff[1]} => $stuff[2]";
}
}
}

抱歉,您可能需要清理/摆弄它才能按照您的意愿进行操作。并检查是否有错误/未定义的条目....

关于php - 如何获取标签后的文字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28124735/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com