1. import subprocess
    2. import sys
    3. import re
    4. import requests
    5. import bs4
    6. def checkTitle(url,wp):
    7. t = requests.get(url, verify=False,timeout=1).text
    8. s = bs4.BeautifulSoup(t, 'html.parser')
    9. print("{}: {}".format(url, re.sub('\n', '', str(s.title))))
    10. wp.write("{}: {}\n".format(url, re.sub('\n', '', str(s.title))))
    11. def main():
    12. fp = open("d:/pythonLab/urls.txt")
    13. wp = open("d:/pythonLab/wrotes.txt","w")
    14. for line in fp.readlines():
    15. s = line.strip()
    16. try:
    17. checkTitle(s,wp)
    18. except:
    19. print("{}: {}".format(s, "[timeout]"))
    20. wp.write("{}: {}\n".format(s, re.sub('\n', '', str(s.title))))
    21. fp.close()
    22. wp.close()
    23. main()