0

i am trying to develop python script to get hosting company info from domaintools.com, below is my script. somthing wrong with this authentication part it returns 403 error.

domain_tools_url = 'https://secure.domaintools.com/log-in/'
username = 'username@gmail.com'
password = 'password'
sys.path.append("./BeautifulSoup")

passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, domain_tools_url, username, password)
authhandler = urllib2.HTTPBasicAuthHandler(passman)
opener=urllib2.build_opener(authhandler, urllib2.HTTPHandler(debuglevel=0))
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
url = "http://whois.domaintools.com/62.75.xxx.xxx"
page = opener.open(url)

can i know how to fix this issue,

Thanks in advance :)

AGR
  • 225
  • 1
  • 2
  • 16
  • [`requests`](http://docs.python-requests.org/en/latest/) makes this a lot nicer - might be worth a try. Basic auth is just `requests.get('http://example.com', auth=('user', 'pass'))` – Alex L Jan 10 '13 at 09:06
  • Hi @AlexL, Thanks for your replay. i have installed requests lib and i have run below script it returns [Response 200] In [6]: requests.get(domain_tools_url, auth=(username, password)) Out[6]: then how can i process this url = "http://whois.domaintools.com/62.75.xxx.xxx" – AGR Jan 10 '13 at 09:18
  • after authentication it returns 403 response 'In [9]: requests.get("http://whois.domaintools.com/62.75.xxx.xxx", auth=(username, password)) Out[9]: In [10]: requests.post("http://whois.domaintools.com/62.75.xxx.xxx") Out[10]: ' – AGR Jan 10 '13 at 09:36
  • Can you log in manually? 403 means that you're getting refused – Alex L Jan 10 '13 at 10:32
  • yes from browser i can login using same auser credentials – AGR Jan 10 '13 at 10:34
  • Using basic auth? Or via a login form? If the latter, you could use [mechanize](http://wwwsearch.sourceforge.net/mechanize/) – Alex L Jan 10 '13 at 10:51
  • Did you ask your provider? Also please use example IPs from RFC5737 for documentation purposes instead of useless and wrong obfuscation. – Patrick Mevzek Jan 03 '18 at 21:54

1 Answers1

0

then how can i process this url = "whois.domaintools.com/62.75.xxx.xxx"

Instead of parsing the html, I suggest using domaintools own API to get the data you need in a straight way without detours (3rd party libraries)

http://www.domaintools.com/api/

DomainTools offers 500 whois queries/month for free, and subscriptions if you need more.

import urllib.request
import json

# please take notice that this is only a sample query 
# you usually need to authenticate your request: http://www.domaintools.com/api/docs/authentication/
data = json.loads(urllib.request.urlopen('http://freeapi.domaintools.com/v1/domaintools.com/whois/').read().decode('utf-8'))

def readValues(obj):
    if isinstance(obj, str):
        print(obj)
    elif isinstance(obj, dict):
        for value in obj.values():
            readValues(value)
    elif isinstance(obj, list):
        for item in obj:
            readValues(item)

readValues(data)

it's in Python 3, fyi

mflatischler
  • 318
  • 1
  • 9