ScrapeboxWorker
Regular Member
- Jul 23, 2012
- 498
- 285
Usage in command line:
Yes very clever moderator... i won't use real epithets that i think what are you...
Now beacuse you deleted my reply, you have:
1. A duplicate thread... great!
2. Old topic was indexed in google and could drive traffic to this website... people looking for "how to remove duplicate domains in python" were coming to this forum and registering... now you have a fresh one that will take ages to index like the old one... great!
3. Instead of keep things in one topic, we will have 22340980 different threads...
Great work!
Code:
python remove_duplicate_domains.py input.txt output.txt --toplevel=true
Code:
import tldextract
import argparse
def rm_dup_domains(args):
file_in = open(args.input, 'r', encoding='utf-8', errors='ignore')
file_out = open(args.output, 'a', encoding='utf-8', errors='ignore')
table = dict()
for line in file_in:
url = tldextract.extract(line.strip())
if args.toplevel is True:
domain = url.registered_domain
elif args.toplevel is False:
if url.subdomain == 'www' or url.subdomain == '':
domain = url.registered_domain
else:
domain = url.fqdn
if domain.startswith('www.'):
domain = url.fqdn.replace('www.', '', 1)
if domain != '':
# lookup for duplicates
if table.get(domain) is not None:
pass
else:
table[domain] = True
file_out.write(f'{domain}\n')
if __name__ == '__main__':
# create command line arguments
parser = argparse.ArgumentParser()
parser.add_argument('input', help='input file', type=str)
parser.add_argument('output', help='output file', type=str)
parser.add_argument('--toplevel', help='keeps only unique top-level domains (removes sub-domains)', type=bool, default=False)
parser.parse_args()
# parse them
args = parser.parse_args()
# run code
rm_dup_domains(args)
Your post in the thread How to remove duplicate domains from text files using python? was deleted. Reason: Thread is from 2015, no need to bump it now
3 minutes ago
Yes very clever moderator... i won't use real epithets that i think what are you...
Now beacuse you deleted my reply, you have:
1. A duplicate thread... great!
2. Old topic was indexed in google and could drive traffic to this website... people looking for "how to remove duplicate domains in python" were coming to this forum and registering... now you have a fresh one that will take ages to index like the old one... great!
3. Instead of keep things in one topic, we will have 22340980 different threads...
Great work!