问题描述:

I have the following code trying to extract the 'photo swipe' section of the site.

It has three separate classes bx-wrapper built - class=bx-viewport - view.

The first two return blank. The view class return an image of the vehicle.

I have searched stack overflow with ref to the spaces and I presume I have the syntax correct for the classes with spaces.

Any ideas what I am doing wrong here.

<?php

require('simple_html_dom.php');

set_time_limit(0);

if (!$html = file_get_html('http://www.citroen.co.uk/new-cars-and-vans/citroen-range/citroen-c3-picasso'))

{

$error = error_get_last();

echo "HTTP request failed. Error was: " . $error['message'];

}

else

{

//echo "The HTML exists so we can use find......";

//echo $html;

//foreach($html->find('div[class="bx-wrapper built"]') as $itemtitle) {

//foreach($html->find('div[class=bx-viewport]') as $itemtitle) {

foreach($html->find('div[class=view]') as $itemtitle)

{

echo $itemtitle;

}

}

?>

网友答案:

The 'photo swipe' sections is not part of the response from http://www.citroen.co.uk/new-cars-and-vans/citroen-range/citroen-c3-picasso, you have to figure out which script is rendering that part.

Hint: view the reponse source code (view-source:http://www.citroen.co.uk/new-cars-and-vans/citroen-range/citroen-c3-picasso) and see the section

    <div class="larger" >
        <script type="text/template" class="viewTpl">
           <div class="views">
                <% if(imgs.length > 0) { %>
                    <% _.each(imgs,function(img,i){ %>
                    <div class="view"<% if(bgs[i]){ %> style="background-image:url(<%= bgs[i] %>);" data-img="<%= bgs[i] %>"<% }; %>>


                    <img class="car" src="<%= img %>" width="717" height="438" alt="" />


                    </div>
                    <% }); %>
                <% } else { %>
                    <% _.each(bgs,function(bg,i){ %>
                    <div class="view" style="background-image:url(<%= bg %>);" data-img="<%= bg %>"></div>
                    <% }); %>
                <% } %>
            </div>
        </script>
    </div>
相关阅读:
Top