import subprocess
import sys
import re
import requests
import bs4
def 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()