我想转换明文公共后缀列表转换为 JSON 对象,以便在我的脚本中使用它。我只想要顶级域名列表。
列表在这里https://publicsuffix.org/list/effective_tld_names.dat
我最初的想法是正则表达式匹配后缀列表的文件,但我不知道如何在 javascript 中正则表达式文件。我对javascript有点陌生。
任何有想法的人,如何实现这一目标。谢谢你
我想转换明文公共后缀列表转换为 JSON 对象,以便在我的脚本中使用它。我只想要顶级域名列表。
列表在这里https://publicsuffix.org/list/effective_tld_names.dat
我最初的想法是正则表达式匹配后缀列表的文件,但我不知道如何在 javascript 中正则表达式文件。我对javascript有点陌生。
任何有想法的人,如何实现这一目标。谢谢你
First off, the list doesn't seem to be allowed to do cross-domain, so direct AJAX to the resource isn't possible.
What you can do is have your server load it for you (PHP: file_get_contents
, JS: http.get
). Then, implement a parser. I'm not familiar with the format of the file, but you can read the file line by line, skip blank lines and lines with //
. Then load them into an array (PHP: array_push
, JS: Array.prototype.push
), serialize (PHP: json_encode
, JS: JSON.serialize
) and ship as JSON to your app.