python - 在 Python 中批量 WHOIS
问题描述
我正在尝试从 python 中的 txt 文件执行批量 WHOIS,我使用了以下代码,但没有得到输出 csv 文件。有人可以告诉我我做错了什么:
import whois
import csv
with open("domains.txt", "r") as f:
domains = f.readlines()
with open("output_file.csv", "wb") as csvfile:
writer = csv.writer(csvfile)
writer.writerow(["Domain", "Registrant Name"])
for domain in domains:
domain = domain.rstrip()
record = whois.whois(domain)
try:
r_name = record.registrant_name
except AttributeError:
r_name = "error"
writer.writerow([domain, r_name])
我在 .py 文件中使用了代码并执行了它,没有任何反应。
然后我还尝试在 Python shell 中使用文件 C:\Users\path...\domains.txt 的完整路径运行(我尝试在路径中使用 1 和 2 个反斜杠)我得到了错误
SyntaxError: invalid syntax
>>> writer = csv.writer(csvfile)
File "<stdin>", line 1
writer = csv.writer(csvfile)
^
IndentationError: unexpected indent
解决方案
推荐阅读
- html - 删除子div和父div之间的单个像素间隙
- python - 如何组合名称包含来自两个字典的单词的 CSV 文件?
- javascript - 由于 CPU 利用率高,Elastic Beanstalk 环境降级
- cucumber - 是否可以在不同的步骤文件中保留与 BDD 相同的会话 ID
- amazon-web-services - Eb Deploy 部署旧运行版本
- oracle - SQL 中的 CASE 表达式引发 ORA-00905
- testing - 在 CakePHP 测试中使用测试数据而不是固定装置
- ios - 导航返回按钮返回错误的视图控制器
- r - 在 R 中创建频率矩阵的聚合函数
- javascript - 如何将“类实例”或“this”推入“函数”方法