Skip to content

Instantly share code, notes, and snippets.

@gillkyle
Created September 3, 2020 20:30
Show Gist options
  • Save gillkyle/3ae3948e5821272322c0f42df8eef9ba to your computer and use it in GitHub Desktop.
Save gillkyle/3ae3948e5821272322c0f42df8eef9ba to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# NOTE: this is a really naive solution that just checks for alt="" in the returned html from the page,
# it would probably give a lot of erroneous results on other projects but got the job done for me.
import urllib.request as urllib2
base_path = "https://gatsbyjs.com"
blog_paths = 'blog_paths.txt'
with open(blog_paths) as fp:
line = fp.readline()
while line:
path = line.strip()
response = urllib2.urlopen(f'{base_path}{path}')
html = response.read()
raw_html = html.decode("utf-8")
if 'alt=""' in raw_html:
print(f'!!! alt text missing in {path} !!!')
else:
print(f'No missing alt text in {path}')
line = fp.readline()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment