Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def parseLink(string):
- global out
- buf = {}
- string = string.replace("http://", "")
- string = string.replace("https://", "")
- string = string.replace("\n", "") #lin/mac
- string = string.replace("\r", "")
- string = string.replace("\r\n", "") #win
- i=j=0
- dp1=dp2=0
- domen=''
- while i < len(string):
- #1 - get domen
- while domen == '':
- if string[i]=='.':
- if dp1==0:
- dp1 = i
- elif dp1 != 0 and dp1 != i and dp2 == 0:
- dp2 = i
- elif dp2 != 0 and dp2 != i:
- dp1 = dp2
- dp2 = i
- elif string[i]=='/':
- if dp2 != 0:
- domen = string[dp1+1:i]
- else:
- domen = string[0:i]
- #print '<domen>: ', domen, '\n<forms>:'
- buf[domen] = []
- break
- i += 1
- #2 - get every form
- if string[i] == '/' and j == 0:
- j = i
- while string[i] != '=' and i < len(string):
- if string[i] in '/?&':
- j = i
- i += 1
- #print string[j+1:i]
- try:
- if string[i] in '?&':
- j = i
- while string[i] != '=' and i < len(string):
- if string[i] in '?&':
- j = i
- i += 1
- #print string[j+1:i]
- if string[j+1:i] not in buf[domen]:
- buf[domen].append(string[j+1:i])
- except BaseException as ex:
- print 'Exception 2: ' + str(ex)
- i+=1
- print buf
- #3 - write in global dict
- if domen in out.keys():
- #for a in buf[domen]:
- if buf[domen] not in out[domen]:
- out[domen].append(a)
- else:
- out[domen] = []
- #for a in buf[domen]:
- out[domen].append(buf[domen])
- print '-----------------------------------'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement