简体   繁体   中英

fetch images from url via CURL crashes on some URLs

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM