PHP SIMPLE DOM - div类

时间:2016-11-10 12:44:18

标签: php

请帮帮我吗?

$html = file_get_html('http://www.csfd.cz/hledat/?q=Rychle+a+zb%C4%9Bsile+2001');

此代码:

<div id="search-films" class="ct-general th-1">
    <h2 class="header">Filmy</h2>
    <div class="content">

        <ul class="ui-image-list js-odd-even">
            <li>
                <a href="/film/1616-rychle-a-zbesile/"><img src="//img.csfd.cz/files/images/film/posters/000/001/1619_405078.jpg?h180" alt="poster" class="film-poster-small image" /></a>
                <div>
                    <h3 class="subject"><a href="/film/1616-rychle-a-zbesile/" class="film c1">Rychle a zběsile</a></h3>



                    <p>Akční / Krimi, USA / Německo, 2001</p>
                    <p>
                        Režie: <a href="/tvurce/2850-rob-cohen/">Rob Cohen</a><br>
                        Hrají: <a href="/tvurce/2218-paul-walker/">Paul Walker</a>, <a href="/tvurce/129-vin-diesel/">Vin Diesel</a><br>
                    </p>
                    <div class="clear"></div>
                </div>
            </li>
        </ul>

如何只有这个:img.csfd.cz/files/images/film/posters/000/001/1619_405078.jpg?h180和这个/ film / 1616-rychle-a-zbesile / ...?谢谢你的帮助

1 个答案:

答案 0 :(得分:0)

如果你想使用simple_html_dom获取src的值,你可以尝试使用代码:

1)来自html内容: -

include("simple_html_dom.php"); // Download it from https://sourceforge.net/projects/simplehtmldom/files/
$html = new simple_html_dom();   
$html->load(YOUR_HTML_CONTENT); 
foreach($html->find('img') as $a)
    echo $a->src;

2)来自网址: -

include("simple_html_dom.php"); 
$html = file_get_html(YOUR_URL); 
foreach($html->find('img') as $a) 
   echo $a->src . '<br>';