Skip to content

Domain to page title

domain-to-title.py


#!/usr/bin/python3
from urllib.request import urlopen

from lxml.html import parse


def report(input_str):
    with open('output.txt', 'a') as f:
        print(input_str)
        f.write(input_str + '\n')


def get_title(target):
    try:
        page = urlopen(target, timeout=2)
        p = parse(page)
        return p.find(".//title").text
    except:
        return "--"


with open("input.txt") as file:
    lines = file.readlines()
    for target_line in lines:
        target = target_line.strip()

        title_domain_http = get_title("http://" + target)
        title_domain_https = get_title("https://" + target)

        report("Domain:{} http:{} https:{}".format(
            target,
            title_domain_http,
            title_domain_https
        ))

dependency

pip install urllib3
pip install lxml

input.txt


example.com
example.pl