我在文本文件中有一个网址列表
我只想提取域名。
运行以下命令:
(Get-Content "c:\temp\test.txt") | ForEach-Object {$url = New-Object System.uri $_;$url.Host} > d:\test.txt
它会生成此错误:
New-Object : Exception calling ".ctor" with "1" argument(s): "Invalid URI: The format of the URI could not be determined."
文本文件只是该域(并且只是域,而不是域后面的路径)一遍又一遍。
对我在哪里胡闹有什么想法吗?
示例文件:
lrp.mxptint.net
lrpush.apxlv.com
lsa.measure.ly
lsa.measure.ly\lsa.js?1449665894174&meta_keywords=Life%2C%20lifestyle%2C%20fashion%2C%20beauty%2C%20Vancouver%2C%20British%20Columbia%2C%20family%2C%20relationships%2C%20home%2C%20blogs%2C%20news%2C%20jobs%2C%20content%2C%20pets%2C%20food%2C%20beauty&autofire=true&windowlocation=www.vancouversun.com\life\diversions lsa.measure.ly\lsa.js?1449665960913&meta_keywords=horoscopes&autofire=true&windowlocation=news.nationalpost.com\category\life
最佳答案
By definition ,URI 以方案开头(通常是协议(protocol),例如 http
)。因此,.Net URI constructor期望字符串以协议(protocol)开头。例如,http://www.example.com
。如果您传入 www.example.com
等,您将收到 Invalid URI
异常。
关于Powershell 从 URL 列表中提取域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34210648/