1

This is my script which is supposed to parse a list of domains (each seperated by returns) in a .txt file, separate them into individual domain names, send a request to a whois site with the domain name, check the response to see if it is available, and if it is, write it to a new file. so i get a list of only available names.

The problem? It's pretty simple i just dont know the language well enough, I dont know how to get the domain name in a string format so that the request to the whois site is like this :

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

Apparently the %s thing is not working.

Code:

#!/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

error in terminal:

python domain.py
Domain Name Availability Scanner.
Enter the Location of the txt file containing your list of domains:
-->a.txt
Traceback (most recent call last):
  File "domain.py", line 13, in <module>
    req = urllib2.Request("http://whois.domaintools.com/%s") % (word)
TypeError: unsupported operand type(s) for %: 'instance' and 'str'
1
  • Did you try reading the error message? Do you understand what it means? Commented Jun 18, 2012 at 17:29

3 Answers 3

5

Fix the parentheses:

req = urllib2.Request("http://whois.domaintools.com/%s" % (word))

As well as:

f.write("%s\n" % word)

:)

Sign up to request clarification or add additional context in comments.

Comments

2

You need to use:

req = urllib2.Request("http://whois.domaintools.com/%s" % word)
# ...
f.write("%s\n" % word)

4 Comments

@SteveTjoa there was only one way to fix it :)
Wow yea I was typing mine and I hit submit and there were two already
Same here :DDDD I'll just +1 all :)
thanks guys, this fixed the error! i am learning python syntax.
2

Use:

f.write("%s\n" % word)

Check out this link, it should explain how this formatting works: http://docs.python.org/release/2.5.2/lib/typesseq-strings.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.