的用户身份验证whois.domaintools.com网站Python纸条

2024-05-23 20:32:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试开发python脚本来获取托管公司的信息域名工具.com,以下是我的剧本。这个认证部分有些问题,它返回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)

我能知道怎么解决这个问题吗

提前感谢:)


Tags: 脚本com信息urldomainusername公司password
1条回答
网友
1楼 · 发布于 2024-05-23 20:32:27

then how can i process this 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)

它在python3中,仅供参考

相关问题 更多 >