File tree Expand file tree Collapse file tree 1 file changed +14
-6
lines changed
Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Original file line number Diff line number Diff line change 1111from enchant import DictWithPWL
1212
1313from lxml .html import document_fromstring , etree
14- from urllib .request import urlopen , URLError
14+ from urllib .request import urlopen , URLError , Request
1515
1616
1717"""
@@ -141,6 +141,13 @@ def static_analysis(self, path):
141141 #######################
142142 # Check that all the links in the markdown cells are valid/accessible.
143143 #######################
144+
145+ # Some sites require a user-agent header as they block requests from scripts. Provide a common user-agent so that we can
146+ # check the links are accessible.
147+ headers = {
148+ "User-Agent" : "Mozilla/5.0 (Macintosh; ARM64 Mac OS X 14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36"
149+ }
150+
144151 no_broken_links = True
145152
146153 cells_and_broken_links = []
@@ -154,12 +161,13 @@ def static_analysis(self, path):
154161 if (
155162 "http" not in document_link [2 ]
156163 ): # Local file (url uses forward slashes, windows backwards).
157- url = "file:///" + os .path .abspath (
158- document_link [2 ]
159- ).replace ("\\ " , "/" )
164+ request = Request (
165+ "file:///"
166+ + os .path .abspath (document_link [2 ]).replace ("\\ " , "/" )
167+ )
160168 else : # Remote file.
161- url = document_link [2 ]
162- urlopen (url )
169+ request = Request ( document_link [2 ], headers = headers )
170+ urlopen (request )
163171 except URLError :
164172 broken_links .append (url )
165173 if broken_links :
You can’t perform that action at this time.
0 commit comments