我想使用 php 或任何语言将原始 html whois 查找数据转换为 json 或 xml

问题描述 投票:0回答:5

我从这里得到了这个whois查询代码。

但我正在获取原始数据或 html 数据..我正在获取输出,但不是像 json 或 xml 那样的可读格式..我如何将其转换为 json .. 粘贴示例输出

ttmm.com domain lookup results from whois.ename.com server:

enter code here Domain Name: ttmm.com
Registry Domain ID:
Registrar WHOIS Server: whois.ename.com
Registrar URL: http://www.ename.net
Updated Date: 1998-11-25 T05:00:00Z
Creation Date: 1998-11-25 T05:00:00Z
Registrar Registration Expiration Date: 2016-11-24 T05:00:00Z
Registrar: eName Technology Co.,Ltd.
Registrar IANA ID: 1331
Registrar Abuse Contact Email: [email protected]
Registrar Abuse Contact Phone: +86.4000044400
Domain Status: clientDeleteProhibited
https://www.icann.org/epp#clientDeleteProhibited
Domain Status: clientTransferProhibited             https://www.icann.org/epp#clientTransferProhibited
 Registry Registrant ID:Not Available From Registry
Registrant Name: chousteven
Registrant Organization: hua you
Registrant Street: an yuan cun daxue cheng
Registrant City: ping xiang shi
Registrant State/Province: jiang xi
Registrant Postal Code: 337000
Registrant Country: CN
Registrant Phone: +86.15979220355
Registrant Phone Ext:
Registrant Fax: +86.15979220355
Registrant Fax Ext:
Registrant Email: [email protected]
Registry Admin ID:Not Available From Registry
Admin Name: chousteven
Admin Organization: hua you
Admin Street: an yuan cun daxue cheng
Admin City: ping xiang shi
Admin State/Province: jiang xi
Admin Postal Code: 337000
Admin Country: CN
Admin Phone: +86.15979220355
Admin Phone Ext:
Admin Fax: +86.15979220355
Admin Fax Ext:
Admin Email: [email protected]
Registry Tech ID:Not Available From Registry
Tech Name: chousteven
Tech Organization: hua you
Tech Street: an yuan cun daxue cheng
Tech City: ping xiang shi
Tech State/Province: jiang xi
Tech Postal Code: 337000
Tech Country: CN
Tech Phone: +86.15979220355
Tech Phone Ext:
Tech Fax: +86.15979220355
Tech Fax Ext:
Tech Email: [email protected]
Name Server: ns1.alidns.com
Name Server: ns2.alidns.com
DNSSEC: unsigned
URL of the ICANN WHOIS Data Problem Reporting System:    http://wdprs.internic.net/
>>> Last update of WHOIS database: 2015-11-19 T12:53:51Z <<<
For more information on Whois status codes, please visit
https://www.icann.org/resources/pages/epp-status-codes-2014-06-16-en
java php html json whois
5个回答
0
投票

大量自定义解析。对不起。没有简单的解决方案。

WHOIS 响应没有标准格式。至少,大多数注册管理机构的响应格式略有不同;此外,.COM 和 .NET 等“精简注册机构”要求每个注册商实施自己的 WHOIS 服务器,每个服务器都有自己略有不同的特殊格式。

正如其他人所指出的,有付费 API 可以为您进行此解析。根据您的需求,这可能是比尝试自己解析数千种不同格式更合适的解决方案。


0
投票

使用 json 无法存储 whois 输出,但可以使用

website = whois.whois(input("Website: ")) open("output.json", "w") as f: f.write(str(website))
保存输出...


0
投票

已经过去很多年了,但如果有人在寻找解决方案。那么就在这里。

据我所知,你不能将列表转换为数组。 php 不知道分离。一个键值对。还有一些其他方法可以将列表转换为数组。

它需要额外的工作,但如果你真的想要,那就试试这些吧

选项1

使用在线工具,例如 https://arraythis.com/。粘贴您的列表,它将转换为数组。它仍然需要一些编辑才能获得正确的数组格式。

如果我输入这个

foobar
foobar: bar

我明白了

array("foobar", "foobar: bar")

但是我想要这个

array("foobar", "foobar" => "bar")

如果你想要一个关联数组,那么你必须使用正则表达式将冒号转换为双箭头运算符

=>
并将字符串括在引号中。如果这工作量太大了。尝试选项 2

选项2

将文本复制并粘贴到任何文本编辑器中。找到所有冒号并将其替换为制表符(空格)。

转到此网站https://tableconvert.com/并粘贴将在表格中输出的数据。向下滚动以选择“Json”选项,它将输出类似这样的内容。

[
    {
        "enter code here Domain Name": "Registrar WHOIS Server",
        "ttmm.com": "whois.ename.com"
    },
    {
        "enter code here Domain Name": "Registrar URL",
        "ttmm.com": "http://www.ename.net"
    },
    {
        "enter code here Domain Name": "Updated Date",
        "ttmm.com": "1998-11-25 T05:00:00Z"
    },
    {
        "enter code here Domain Name": "Creation Date",
        "ttmm.com": "1998-11-25 T05:00:00Z"
    },
    {
        "enter code here Domain Name": "Registrar Registration Expiration Date",
        "ttmm.com": "2016-11-24 T05:00:00Z"
    }
]

-1
投票

我正在运行 whois API 服务 (https://websiteapi.com/),注册管理机构之间的各种响应每天都让我感到惊讶,直到处理完所有这些为止。

除了缺乏通用格式之外,当不使用处理这些情况的服务时,返回不一致格式的给定注册表确实很难处理。


-3
投票

将文本拆分为行。 阅读每一行。 检查每一行是否有过期关键字。 如果找到,请尝试返回所需的内容。

© www.soinside.com 2019 - 2024. All rights reserved.