标签:exception header lines www charm 一个 pychar main lin
import os, sys from socket import gethostbyname # DOMAIN= "G:/PycharmProject/fullstack2/week1/domain.txt" def main(): # domain.txt里面存储的是需要批量解析的域名列表,一行一个 with open("domains.txt", ‘r‘) as f: for line in f.readlines(): try: host = gethostbyname(line.strip(‘\n‘)) except Exception as e: print(e) else: # result.txt里面存储的是批量解析后的结果,不用提前创建 with open(‘result.txt‘, ‘a+‘) as r: r.write(line.strip(‘\n‘) + ‘ ‘) r.write(host + ‘\n‘) if __name__ == ‘__main__‘: main()
转载博客:钟桂耀
标签:exception header lines www charm 一个 pychar main lin
原文地址:https://www.cnblogs.com/qiqi-yhq/p/12054297.html