作者:yjlz2012 | 来源:互联网 | 2023-01-28 09:41
IwanttocheckiftheURLthattheuserinputsisinfactavalidpage.我想检查用户输入的URL是否为有效页面。Itri
I want to check if the URL that the user inputs is in fact a valid page.
我想检查用户输入的URL是否为有效页面。
I tried:
我试着:
if Nokogiri::HTML(open("http://example.com"))
#DO REQUIRED TASK
end
But that immediately throws an error upon attempting to open the page. I want to return the result of whether it is a document of any kind.
但是当试图打开页面时,会立即抛出一个错误。我想返回它是否是任何类型的文档的结果。
I either get the error:
我要么得到错误:
no such file or directory
or:
或者:
getaddrinfo: Name or service not known
depending on how I try to make the check.
这要看我如何结账。
3 个解决方案