【发布时间】:2013-03-09 19:12:51
【问题描述】:
我想尝试获取我在 IcheckMovies 网站上查看的最新电影并将其显示在我的网站上。我不知道怎么做,我已经阅读了 php_get_contents() 然后获取了一个元素,但是我想要的特定元素在 DOM 结构中相当深入。它在一个 div 中的一个 div 中的一个列表中的一个 ...
所以,这是我想从中获取内容的链接:http://www.icheckmovies.com/profiles/robinwatchesmovies,我想获取列表中电影的第一个标题。
提前非常感谢!
编辑:
所以使用 file_get_contents() 方法
<?php
$html = file_get_contents('http://www.icheckmovies.com/profiles/robinwatchesmovies/');
echo $html;
?>
我得到了这个 html 输出。现在,我只需要获取'Smashed',以便在列表中的 div 中的 div 中的 h3 中的 href 链接的内容。这是我不知道如何获得它的地方。
...
<div class="span-7">
<h2>Checks</h2>
<ol class="itemList">
<li class="listItem listItemSmall listItemMovie movie">
<div class="listImage listImageCover">
<a class="dvdCoverSmall" title="View detailed information on Smashed (2012)" href="/movies/smashed/"></a>
<div class="coverImage" style="background: url(/var/covers/small/10/1097928.jpg);"></div>
</div>
<h3>
<a title="View detailed information on Smashed (2012)" href="/movies/smashed/">Smashed</a>
</h3>
<span class="info">6 days ago</span>
</li>
<li class="listItem listItemSmall listItemMovie movie">
<li class="listItem listItemSmall listItemMovie movie">
</ol>
<span>
</div>
...
【问题讨论】:
-
看看HttpRequestphp.net/manual/en/class.httprequest.php
-
ID 元素在 html 中的深度无关紧要……元素的 ID 应该是唯一的。发布您尝试使用的代码
-
嗨,这很模糊,您基本上已经提到了最常见的解决方案 -
file_get_contents()并使用 HTML parser. 解析 DOM 有很多示例如何在以下情况下执行此操作例如谷歌搜索Get specific html content from other site with PHP。您是否对此感到困惑? -
很抱歉,我不太清楚。我已添加代码,希望对您有所帮助。
-
可以通过在文本周围放置重音`字符来突出显示您想要的html
标签: php dom file-get-contents