#NEWLINE# def url_normalize( url , seed_page ) : #NEWLINE# #INDENT# url = url . lower ( ) #NEWLINE# s = urlparse ( url ) #NEWLINE# seed_page = seed_page . lower ( ) #NEWLINE# t = urlparse ( seed_page ) #NEWLINE# flag = 0 #NEWLINE# if ( url == '/' ) : #NEWLINE# #INDENT# url = seed_page #NEWLINE# flag = 0 #NEWLINE# print ( url ) #NEWLINE# #UNINDENT# if ( s . netloc == '' ) : #NEWLINE# #INDENT# path = url . find ( '/' ) #NEWLINE# if ( path != ( - 1 ) ) : #NEWLINE# #INDENT# url = url [ path : ] #NEWLINE# url = ( seed_page + url ) #NEWLINE# flag = 0 #NEWLINE# s = urlparse ( url ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# url = url #NEWLINE# flag = 0 #NEWLINE# #UNINDENT# #UNINDENT# if ( not s . scheme ) : #NEWLINE# #INDENT# url = ( 'http://' + url ) #NEWLINE# flag = 0 #NEWLINE# s = urlparse ( url ) #NEWLINE# #UNINDENT# if ( '#' in url ) : #NEWLINE# #INDENT# url = url [ : url . find ( '#' ) ] #NEWLINE# #UNINDENT# if ( '?' in url ) : #NEWLINE# #INDENT# url = url [ : url . find ( '?' ) ] #NEWLINE# #UNINDENT# if ( 'www' not in url ) : #NEWLINE# #INDENT# url = ( 'www.' [ : 7 ] + url [ 7 : ] ) #NEWLINE# flag = 0 #NEWLINE# s = urlparse ( url ) #NEWLINE# #UNINDENT# if ( 'http' not in url ) : #NEWLINE# #INDENT# url = ( 'http://' + url ) #NEWLINE# flag = 0 #NEWLINE# s = urlparse ( url ) #NEWLINE# #UNINDENT# if ( url [ ( len ( url ) - 1 ) ] == '/' ) : #NEWLINE# #INDENT# url = url [ : ( - 1 ) ] #NEWLINE# flag = 0 #NEWLINE# #UNINDENT# if ( s . netloc != t . netloc ) : #NEWLINE# #INDENT# s = urlparse ( url ) #NEWLINE# url = url #NEWLINE# flag = 1 #NEWLINE# #UNINDENT# if ( flag == 0 ) : #NEWLINE# #INDENT# return url #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return 'Invalid URL'