0

I was trying to use the script given here php get all the images from url which width and height >=200 more quicker

I downloaded and used the simple_html_dom.php given here http://sourceforge.net/projects/simplehtmldom/

It works for most urls, but when I use something like http://www1.macys.com/shop/mens-clothing/mens-athletic-wear?id=59165&edge=hybrid&cm_sp=us_men%27s-men%27s-apparel-activewear-_-t-shirts#!fn=APPAREL_TYPE%3DT-Shirts%26sortBy%3DORIGINAL%26productsPerPage%3D40&!qvp=iqvp

The script simply crashes. Can someone help?

EDIT: I put error reporting and it gives this.

Fatal error: Call to a member function find() on a non-object in /var/www/smartbiz/smartbiz/test2.php on line 16

line 16:if ($html->find ( 'img' )) {

EDIT2: Not sure if this is relevant PHP simple html dom: apache crashes, PHP simple html dom: apache crashes

Community
  • 1
  • 1
aVC
  • 2,254
  • 2
  • 24
  • 46
  • If it's the error "call to function on a non-object", then obviously you need to check the contents of the `$html` before the `if ($html->find ( 'img' ))` line. But I think there are more errors, probably with the maximum content size. It's a matter of debugging, not asking a single question. – Ranty Oct 28 '12 at 11:14
  • you need to figure what exactly is the error. I've met cases, when the page was too big to cause the memory limit. Check web server logs to see what's the exact error. – Ranty Oct 28 '12 at 18:54

1 Answers1

0

You can wrap your code in a try-catch statement.

<?
try{

   // Your image checking code..

}catch( Exception $e ){
   echo "Image not found: $e";
}
?>

It sounds like the error is that the HTML is not loading. We'll need more of your code otherwise I can just give you basic debugging advise.

  1. Copy and Paste a link that 'fails' into your browser and check that it's working.
  2. Try loading the HTML into the Simple HTML DOM in another way.
  3. If those don't work, vardump the $html variable to see what's going on.
  4. If the loop is working for some and not others, what's different? The URL structure, character encoding present/missing?

Try putting the HTML in another way.

$html = str_get_html( file_get_contents( $YOUR_URL ) );

I hope this helps.

Adam
  • 1,080
  • 1
  • 9
  • 17