如何在PHP中抓取嵌套元素


How to scrape a nested element in PHP?

我正在尝试抓取此URL:

http://movietube.cc/search.php

我需要每部电影的名字,图片和链接。我已尝试嵌套<tr>元素

<?php
include('simple_html_dom.php');
$html = file_get_html('http://movietube.cc/search.php');

// Find all links 
foreach($html->find('tr ') as $element) 
       echo $element->val. '<br>';
 ?>

我做不到。我是刮痧新手,有人能告诉我怎么做吗?

<?php
include('simple_html_dom.php');
//set POST variables
$fields = array(
    'c' => song,
    'a' => retrieve,
    'p' => urlencode('{"Page":"1","NextToken":"","VideoYoutubeType":"English","Genere":"","Year":"","Sortby":"Score"}')
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
$curl = curl_init(); 
curl_setopt($curl, CURLOPT_URL, 'http://movietube.cc/index.php');  
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);  
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10); 
curl_setopt($curl, CURLOPT_POST, count($fields));
curl_setopt($curl, CURLOPT_POSTFIELDS, $fields_string);
$str = curl_exec($curl);  
curl_close($curl);  
$html = str_get_html($str); //echo $html;
$img = array(); $title = array(); $url = array();
// Find all images 
foreach($html->find('a[target=_blank] img[bgcolor=##000000]') as $element) {
    $img[] = $element->src;
    //echo $element->src. '<br>';
}
// Find all titles 
foreach($html->find('div.dtl h1.text a[target=_blank]') as $element) {
    $title[] = $element->plaintext;
    //echo $element->plaintext. '<br>';
}
// Find all urls 
foreach($html->find('div.dtl h1.text a[target=_blank]') as $element) {
    $url[] = $element->href;
    //echo $element->href. '<br>';
}
//Print results
echo "<pre>"; print_r($img);   echo "</pre>";
echo "<pre>"; print_r($title); echo "</pre>";
echo "<pre>"; print_r($url);   echo "</pre>";
?>

这是你需要使用的代码:如果你想获得其他语言或其他东西的结果,你可以编辑POST变量。我决定将所有图像的标题和url放在数组中(img、title和url)。