#NEWLINE# def main( ) : #NEWLINE# #INDENT# parser = optparse . OptionParser ( ) #NEWLINE# parser . add_option ( '--debug' , dest = 'debug' , action = 'store_true' , help = 'debug mode' , default = False ) #NEWLINE# parser . add_option ( '--url' , dest = 'url' , help = 'fetch this URL' , default = None ) #NEWLINE# parser . add_option ( '--file' , dest = 'inputfile' , help = 'parse this HTML file' , default = None ) #NEWLINE# parser . add_option ( '--script' , dest = 'parselet' , help = 'Parsley script filename' , default = None ) #NEWLINE# ( options , args ) = parser . parse_args ( ) #NEWLINE# if ( not options . parselet ) : #NEWLINE# #INDENT# print ( 'You must provide a Parsley script' ) #NEWLINE# return #NEWLINE# #UNINDENT# if ( ( not options . url ) and ( not fp . inputfile ) ) : #NEWLINE# #INDENT# print ( 'You must provide an URL' ) #NEWLINE# return #NEWLINE# #UNINDENT# with open ( options . parselet ) as fp : #NEWLINE# #INDENT# extractor = parslepy . Parselet . from_jsonfile ( fp , options . debug ) #NEWLINE# output = extractor . parse ( ( options . url or options . inputfile ) ) #NEWLINE# pprint . pprint ( output )