import subprocessimport sysimport reimport requestsimport bs4def checkTitle(url,wp): t = requests.get(url, verify=False,timeout=1).text s = bs4.BeautifulSoup(t, 'html.parser') print("{}: {}".format(url, re.sub('\n', '', str(s.title)))) wp.write("{}: {}\n".format(url, re.sub('\n', '', str(s.title))))def main(): fp = open("d:/pythonLab/urls.txt") wp = open("d:/pythonLab/wrotes.txt","w") for line in fp.readlines(): s = line.strip() try: checkTitle(s,wp) except: print("{}: {}".format(s, "[timeout]")) wp.write("{}: {}\n".format(s, re.sub('\n', '', str(s.title)))) fp.close() wp.close()main()