使用simplehtmldom(php)来检索不适用于某些网站的网站图像如何修复


Using simplehtmldom (php) to retrieve site images not working on some sites how to fix?

我试图从任何有图像的网站上检索图像。我在php中使用simplehtmldom lib来废弃用户选择的HTML页面,只获取该网站的图像,有些网站的lib设法获得了图片错误分配的网站,它没有。它只是获取空结果,例如此网站:http://www.outfitfashion.com/

我正在尝试获取此图像:
http://www.outfitfashion.com/images/lifestyle/SS12/home.jpg
它永远不会得到

$url = $urlname;
    $html = file_get_html($url);
    $counter = 0; 
    $strTmp ="";
    foreach($html->find('img') as $element) {
        $strTmp = url_to_absolute($url, $element->src);      
        $pattern0 = "/'.(?=jpg|gif|png|jpeg|bmp)/i";
        if(preg_match($pattern0,$strTmp))
        {            
            $user_albums_photos[$counter] = $strTmp;
            $counter++;
        }
    }
    $comma_separated = implode(",", $user_albums_photos);

有更好的方法吗?可能是php中的其他库,可以处理复杂的HTML页面。

它没有拾取它,因为图像被设置为<div>的CSS background属性,而不在<img />标记内。因此不存在src=""属性。

如果你想获取背景,你应该在<head>标签内查看样式表,然后检查它们。