0

domaintools.com からホスティング会社の情報を取得するための Python スクリプトを開発しようとしています。以下は私のスクリプトです。この認証部分に何か問題があると、403 エラーが返されます。

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)

この問題を解決する方法を教えてください。

前もって感謝します :)

4

1 に答える 1

0

次に、この URL = "whois.domaintools.com/62.75.xxx.xxx" を処理するにはどうすればよいですか

HTML を解析する代わりに、domaintools 独自の API を使用して、必要なデータを迂回せずに直接取得することをお勧めします (サードパーティ ライブラリ)。

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

DomainTools では、毎月 500 件の whois クエリを無料で提供しており、さらに必要な場合はサブスクリプションを提供しています。

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)

それはPython 3にあります、fyi

于 2013-01-12T19:25:24.753 に答える