小编Joh*_*son的帖子

Python简单字符串格式错误

这是我的脚本,它应该解析域(由每个分隔回报)的.txt文件的列表,它们分成单独的域名,发送请求到域名注册网站域名为,检查响应,看是否它是可用的,如果是,则将其写入新文件.所以我得到一个只有可用名称的列表.

问题?这很简单,我只是不太了解语言,我不知道如何以字符串格式获取域名,以便对whois站点的请求是这样的:

http://whois.domaintools.com/google.com

显然%s的东西不起作用.

码:

#!/usr/bin/python
import urllib2, urllib
print "Domain Name Availability Scanner."
print "Enter the Location of the txt file containing your list of domains:"
path = raw_input("-->")

wordfile = open(path, "r")
words = wordfile.read().split("n")
words = map(lambda x: x.rstrip(), words)
wordfile.close()

for word in words:
    req = urllib2.Request("http://whois.domaintools.com/%s") % (word)
    source = urllib2.urlopen(req).read()
    if "This domain name is not registered" in source:
    f = open("success.txt", "a")
    f.write("%s\n") % (word)
    f.close()
  break
Run Code Online (Sandbox Code Playgroud)

终端错误:

python domain.py
Domain Name Availability …
Run Code Online (Sandbox Code Playgroud)

python string

1
推荐指数
1
解决办法
208
查看次数

标签 统计

python ×1

string ×1