This Python script helps you with alternative text for images on your site. The way Google indexes images for SEO is by reading the alt text of the image. This script uses Google Vision API to recommend you alt text on your site. It can be current images with alt text or images without alt text.
To use this script, there are some libraries and some setups to run it successfully.
First, we need to install the important libraries we are using for that we can run our requirements.txt
pip install requirements.txt
Once we have our libraries installed, we need to install chromedriver , and on line 50 we need to specify the executable_path='
driver = webdriver.Chrome(options=chrome_options,executable_path='/usr/local/bin/chromedriver') # <----Here
To learn more about how to set up this, you can click here
Finally, we need to get our Google vision API activated and get our .json
file with our keys.
To activate the API and get the .json API with your private key, please follow Google instructions here. If you have any problem, please create an issue, and I will be happy to help.
Once you have the file you need to update line 223 and add your path to you .json file
client = vision.ImageAnnotatorClient.from_service_account_json("add your PATH here")
Using this script is very easy. You can import it and set a new url variable and then call the get_images(ulr) function.
** Dont add https://
import alt
url = 'www.uselessthingstobuy.com/gifts/gifts-under-25/' # Overwrites url in the script and dont include https://
get_images(url) #call function with our new URL
Once you run this it will go and look for top 15 images and alt text that your page have and will createa DataFrame with current alt text, URL and recommended alt text.
If you want to remove the limit, you can comment it out by adding a # on line 175
#limiting only top 11 images from list( So that the api costs are not that high :D )
df = df.head(15)
Pull requests are welcome. For significant changes, please open an issue first to discuss what you would like to change.