Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scan site for images and alt attributes [closed]

We'd like to run a scan on our site that returns a report with the following:

  1. each image tag found and a visual representation of that image on the report
  2. the alt attribute for that image (also identify if an alt attribute isn't found)

Is there a simple tool that does this? We're attempting to check for alt attributes, and make sure the alt attributes accurately describe to the image they represent. That's why the visual representation in the report is important.

like image 341
Alex Avatar asked Jan 06 '11 15:01

Alex


People also ask

How do I fix missing ALT attributes?

What to do (in short) To fix an Image Missing Alternative Text error, you will need to add an alt tag to the image with appropriate text describing the purpose of the image in the page. If the image is decorative, the alt attribute can be empty, but the HTML alt="" tag still needs to be present.

What happens when you do not provide alt attribute for an image tag?

The required alt attribute specifies an alternate text for an image, if the image cannot be displayed. The alt attribute provides alternative information for an image if a user for some reason cannot view it (because of slow connection, an error in the src attribute, or if the user uses a screen reader).


1 Answers

Try the Python package Beautiful Soup. It will parse all of your HTML for you in a really simple statement. Try this code:

website = urllib2.urlopen(url)
websitehtml = website.read()
soup = BeautifulSoup(websitehtml)
matches = soup.findAll('img')
for row in matches:
    print row['src']
    print row['alt']

From here use row['src'] to set the src of an image and print out alt next to it.

like image 78
Jeremy Thiesen Avatar answered Sep 24 '22 14:09

Jeremy Thiesen