python 2.7 and 3.5 compatibility

This commit is contained in:
Terrtia 2018-04-18 13:51:09 +02:00
parent 388f14df2b
commit 6e2dc62f6b

View file

@ -8,7 +8,14 @@ import re
import dns.resolver
import IPy
import socket
import urllib.request
try:
#python 3
import urllib.request as urllib
except:
#python 2
import urllib2 as urllib
__author__ = "Alexandre Dulaunoy"
__copyright__ = "Copyright 2012-2017, Alexandre Dulaunoy"
@ -82,9 +89,9 @@ class Extract:
def __updatelisttld(self):
ianatldlist = "https://data.iana.org/TLD/tlds-alpha-by-domain.txt"
req = urllib.request.Request(ianatldlist)
req = urllib.Request(ianatldlist)
req.add_header('User-Agent', 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0')
tlds = ( urllib.request.urlopen(req).read() ).decode('utf8')
tlds = ( urllib.urlopen(req).read() ).decode('utf8')
tlds = tlds.split("\n")
for tld in tlds:
self.listtld.append(tld.lower())