반응형
url parser
''' write by kyoung chip ,jang url parser ''' import urlparse class CUrlParser : def __init__(self) : self.url = "" self.url_split = "" self.url_query = "" self.url_parse_query = "" def setUrl( self, url ) : self.url = url def urlParse1( self ) : self.url_split = urlparse.urlsplit( self.url ) self.url_parse_query = urlparse.parse_qs(urlparse.urlsplit( self.url ).query) ''' SplitResult( scheme='http', netloc='media.daum.net', path='/issue/470288', query='selectedNewsId=20171002222457920&rcmd=rn', fragment='') ''' for us in range( 0 , len( self.url_split ) -2 ) : print self.url_split[us] self.url_query = self.url_split[ len( self.url_split ) -2 ] print "[*] query = %s " % self.url_query print "[*] --- query ---- " for query in self.url_parse_query : print "%s=%s" % ( query , self.url_parse_query[query][0] ) def urlParse2( self ) : self.url_split = urlparse.urlsplit( self.url ) self.url_parse_query = urlparse.parse_qs(urlparse.urlsplit( self.url ).query) ''' SplitResult( scheme='http', netloc='media.daum.net', path='/issue/470288', query='selectedNewsId=20171002222457920&rcmd=rn', fragment='') ''' print self.url_split.scheme print self.url_split.netloc print self.url_split.path print self.url_split.query print "[*] --- query ---- " for query in self.url_parse_query : print "%s=%s" % ( query , self.url_parse_query[query][0] ) def urlMerge( self ) : pass if __name__ == '__main__': c = CUrlParser() c.setUrl("http://media.daum.net/issue/470288?selectedNewsId=20171002222457920&rcmd=rn") c.urlParse1() c.urlParse2()
반응형
'Python > 0x01-url' 카테고리의 다른 글
wget (0) | 2017.10.06 |
---|---|
html parser class ][ security focus title과 link정보 가져오기 (0) | 2017.10.05 |
html parser class ][ 보안뉴스 가장 많이 본 뉴스 keyword 가져오기 (0) | 2017.10.03 |
request class (0) | 2017.10.03 |