<s> try : <EOL> from urllib . parse import urljoin <EOL> except ImportError : <EOL> from urlparse import urljoin <EOL> import re <EOL> from . import Crawler , CrawlerError <EOL> class NineGag ( Crawler ) : <EOL> """<STR_LIT>""" <EOL> __uri = "<STR_LIT>" <EOL> __next = "<STR_LIT>" <EOL> __site = "<STR_LIT>" <EOL> __RE_post_container = re . compile ( "<STR_LIT>" ) <EOL> @ staticmethod <EOL> def __build_uri ( uri ) : <EOL> return uri <EOL> def _restart_at_front ( self ) : <EOL> self . __next = self . __uri <EOL> def __init__ ( self , uri , site ) : <EOL> self . __site = site <EOL> self . __uri = self . __class__ . __build_uri ( uri ) <EOL> self . _restart_at_front ( ) <EOL> def _crawl ( self ) : <EOL> uri = self . __next <EOL> self . __class__ . _log ( "<STR_LIT>" , "<STR_LIT>" % ( self . __class__ . __name__ , uri ) ) <EOL> ( page , base , _ ) = self . __class__ . _fetch_remote_html ( uri ) <EOL> if not page : <EOL> self . __class__ . _log ( "<STR_LIT>" , "<STR_LIT>" % ( self . __class__ . __name__ , uri ) ) <EOL> return <EOL> _more = page . find ( "<STR_LIT>" , { "<STR_LIT:class>" : "<STR_LIT>" } ) <EOL> _next = None <EOL> if _more : <EOL> _more = _more . find ( "<STR_LIT:a>" , { "<STR_LIT:class>" : "<STR_LIT>" , "<STR_LIT>" : True } ) <EOL> if _more : <EOL> _next = urljoin ( base , _more [ "<STR_LIT>" ] ) <EOL> if _next : <EOL> self . __next = _next <EOL> else : <EOL> self . __class__ . _log ( "<STR_LIT>" , "<STR_LIT>" % ( self . __class__ . __name__ , uri ) ) <EOL> images_added = <NUM_LIT:0> <EOL> for con in page . find_all ( "<STR_LIT>" , { "<STR_LIT:class>" : self . __class__ . __RE_post_container } ) : <EOL> image = None <EOL> image_inline = con . find ( "<STR_LIT>" , { "<STR_LIT:class>" : "<STR_LIT>" , "<STR_LIT>" : True } ) <EOL> if image_inline : <EOL> image = image_inline [ '<STR_LIT>' ] <EOL> image_src = con . find ( '<STR_LIT>' , { "<STR_LIT:class>" : "<STR_LIT>" , "<STR_LIT:src>" : True } ) <EOL> if image_src : <EOL> image = image_src [ '<STR_LIT:src>' ] <EOL> if image : <EOL> if self . _add_image ( urljoin ( base , image ) , self . __site ) : <EOL> images_added += <NUM_LIT:1> <EOL> if not images_added : <EOL> self . __class__ . _log ( "<STR_LIT>" , "<STR_LIT>" % ( self . __class__ . __name__ , uri ) ) </s>
