Function Repository Resource:

CheckHyperlinks

Source Notebook

Checks hyperlinks in an expression, webpage, or notebook, on your computer or in the cloud

Contributed by: Wolfram Staff

ResourceFunction["CheckHyperlinks"][expr]

checks hyperlinks in expr and reports which can be successfully followed and which are broken.

ResourceFunction["CheckHyperlinks"][expr,props]

gives only the specified properties props of the hyperlinks.

Details and Options

ResourceFunction["CheckHyperlinks"][expr,] checks hyperlinks either in expr itself or in an object to which expr is pointing.
The following expressions are interpreted as pointers to the target object:
CloudObjectcloud object representing an API or a notebook
NotebookObjectopen notebook in the front end
URLURL object
Filefile object
Stringstring representing a URL, or a path to a notebook or HTML file
Strings that do not point to a notebook or HTML file give an error.
Unless expr has special interpretation rules, ResourceFunction["CheckHyperlinks"] follows only elements with the explicit head Hyperlink.
Notebook expressions have special interpretation rules.
ResourceFunction["CheckHyperlinks"][obj] returns results in the form: <|"Valid"{vurl1,vurl2,},"Broken"{burl1,burl2,},"BrokenData"assoc|>, where vurli and burli are vaild and broken urls, respectively, and the association assoc is in the form <|burl1resp1,burl2resp2,|>, where respi are response or failure objects for burli.
Possible properties in ResourceFunction["CheckHyperlinks"][obj,props] are:
"Valid"valid URLs
"Broken"broken URLs
"BrokenData"association giving broken URLs and corresponding response or failure objects

Examples

Basic Examples (5) 

Check a hyperlink:

In[1]:=
ResourceFunction["CheckHyperlinks"][
 Hyperlink["https://www.wolfram.com"]]
Out[1]=

Check only for broken links:

In[2]:=
ResourceFunction["CheckHyperlinks"][
 Hyperlink["https://www.wolfram.com/broken"], "Broken"]
Out[2]=

Check several hyperlinks:

In[3]:=
{Hyperlink["https://www.wolfram.com"], Hyperlink["bad URL", "https://wolfram.com/does-not-exist"]}
Out[3]=
In[4]:=
ResourceFunction["CheckHyperlinks"][%]
Out[4]=

Check hyperlinks on a webpage:

In[5]:=
ResourceFunction["CheckHyperlinks"]["https://www.wolframalpha.com"]
Out[5]=

Check hyperlinks in a cloud object:

In[6]:=
co = CloudPublish[{Hyperlink["https://www.wolfram.com"], Hyperlink["http://www.wolfram.com/does-not-exist"]}]
Out[6]=
In[7]:=
ResourceFunction["CheckHyperlinks"][%]
Out[7]=

Check the same object given as a URL:

In[8]:=
First[co]
Out[8]=
In[9]:=
ResourceFunction["CheckHyperlinks"][%]
Out[9]=

Scope (7) 

Check hyperlinks in an expression:

In[10]:=
ResourceFunction["CheckHyperlinks"][
 Hold[If[True, Hyperlink["https://www.wolfram.com"], Hyperlink["https://www.wolfram.com/2"], Hyperlink["https://www.wolfram.com/3"]]]]
Out[10]=

Check hyperlinks in a cloud object:

In[11]:=
ResourceFunction["CheckHyperlinks"][
 CloudPublish[Hyperlink["https://www.wolfram.com"]]]
Out[11]=

Check hyperlinks in the body of a cloud API function:

In[12]:=
CloudPublish[
 Delayed[{Hyperlink["https://www.wolfram.com"]; DateString[]}]]
Out[12]=
In[13]:=
ResourceFunction["CheckHyperlinks"][%]
Out[13]=

Check hyperlinks in an open notebook object:

In[14]:=
nb = CreateDocument[{TextCell["S1", "Section"], TextCell[Hyperlink["Text link", "http://www.wolfram.com"], "Text"], ExpressionCell[
     Hyperlink["Input cell link", "https://www.wolfram.com/1"], "Input"]}];
In[15]:=
ResourceFunction["CheckHyperlinks"][nb]
Out[15]=

Check hyperlinks in a notebook file, using different representations a pointer to the file:

In[16]:=
file = FileNameJoin[{$InstallationDirectory, "Documentation", "English", "System", "ReferencePages", "Symbols", "Hyperlink.nb"}];
In[17]:=
ResourceFunction["CheckHyperlinks"][file]
Out[17]=
In[18]:=
ResourceFunction["CheckHyperlinks"][File[file]]
Out[18]=
In[19]:=
ResourceFunction["CheckHyperlinks"]["file://" <> file]
Out[19]=

Check hyperlinks in a Notebook object:

In[20]:=
ResourceFunction["CheckHyperlinks"][
 Notebook[{Cell[
    BoxData[TemplateBox[{"link", "http://www.wolfram.com"}, "HyperlinkURL"]], "Text"]}]]
Out[20]=

Check only for the specified properties of the links:

In[21]:=
expr = {Hyperlink["https://www.wolfram.com"], Hyperlink["https://www.wolfram.com/broken"]}
Out[21]=
In[22]:=
ResourceFunction["CheckHyperlinks"][expr, "Valid"]
Out[22]=
In[23]:=
ResourceFunction["CheckHyperlinks"][expr, "Broken"]
Out[23]=
In[24]:=
ResourceFunction["CheckHyperlinks"][expr, {"Valid", "BrokenData"}]
Out[24]=

Possible Issues (2) 

Some front end objects are not currently recognized as special objects:

In[25]:=
cell = Cell[
   BoxData[TemplateBox[{"link", "http://www.wolfram.com"}, "HyperlinkURL"]], "Text"];
In[26]:=
ResourceFunction["CheckHyperlinks"][cell]
Out[26]=

Apply the Notebook wrapper to check links:

In[27]:=
ResourceFunction["CheckHyperlinks"][Notebook[{cell}]]
Out[27]=

Version History

  • 1.0.0 – 24 October 2019

Author Notes

CheckHyperlinks could have an AuthenticationRules option to handle authentication in sub-URLs. (Currently, it simply treats 401 authentication failure codes as “valid”.)

Hyperlinks with Wolfram Language’s own URI are currently ignored (e.g., “paclet:ref/foo”.

Properly integrating options with all the underlying functions will require a little more work. For now, use at your own risk.

License Information