如何使用 php 代码显示来自网站子页面的图像 URL


How to display image url from website sub pages using php code

我正在使用下面提到的php代码来显示网页中的图像。下面提到的代码能够显示来自主页的图像 URL,但无法显示来自子页面的图像 URL。

enter code here
<?php
include_once('simple_html_dom.php');
$target_url = "http://fffmovieposters.com/";
$html = new simple_html_dom();
$html->load_file($target_url);
foreach($html->find('img') as $img)
{
echo $img->src."<br />";
echo $img."<br/>";
}
?>

如果您所说的子页面是指http://fffmovieposters.com链接到的页面,那么该脚本当然不会显示任何这些页面,因为您没有加载这些页面。

你基本上必须编写一个蜘蛛,它不仅可以查找图像,还可以找到锚标签,然后对这些链接重复该过程。请记住添加一些过滤器,这样您就不会多次处理页面或通过以下外部链接开始处理整个互联网。

伪代码

$todo = ['http://fffmovieposters.com'];
$done = [];
$images = [];
while( ! empty($todo))
    $link = array_shift($todo);
    $done[] = $link;
    $html = get html;
    $images += find <img> tags
    $newLinks = find <a> tags
    remove all external links and all links already in $done from $newLinks
    $todo += $newLinks;

或者类似的东西...