One of the most practical and inspiring talks at last week’s Brighton SEO came from Anita Valentinova, on the topic of using Python to automate SEO.
Valentinova is a senior SEO specialist at VistaPrint, a company that runs 21 websites with over 40,000 webpages.
Unsurprisingly, automation is an attractive prospect when working at that scale and though Valentinova is a relative newcomer to Python, she explained how excited she was to try out new scripts in her day-to-day role.
At a conference where artificial intelligence and voice search seemed to be the topics on everyone’s lips, I found Valentinova’s talk refreshing in its advocacy of just getting on and setting up some simple (ish) alerts to make your workflow more manageable.
What is Python?
Python is a very popular open-source computer programming language, supported by a large community of programmers. It has been used, amongst many other things, in natural language processing and as the main user language for the Raspberry Pi.
Python is one of the chief languages for scripts, but if, like me, you’ve only ever messed about with HTML and CSS, you can take heart from Python’s philosophy as described in the Zen of Python:
- Beautiful is better than ugly
- Explicit is better than implicit
- Simple is better than complex
- Complex is better than complicated
- Readability counts
What use is Python for the typical SEO?
You may already use third-party software such as Screaming Frog, and Valentinova posed the question, “Isn’t that enough?” Well, she says, not always. Scripts allow the SEO to be proactive, not reactive, receiving notifications at any time.
Python scripts can be used to automate repetitive but necessary tasks. You might use them to compare canonical URLs or to look for changes in indexation. Or alternatively you may want to scrape competitor pages and keep an eye on changes to their products and pricing.
Similarly, you could use Python to check on your own data, such as headings and structured data. Valentinova gave one example, citing instances where multiple content editors are making changes to data on key product pages. In this scenario, the SEO may not receive notifications to make them aware of these changes. If the changes aren’t communicated to the SEO team, it could impact rankings, and therefore a script can be used to provide a timely alert.
The Python script parses HTML and compares current value with expected values, sending an email alert that highlights any discrepancies. This type of activity could be taken further and used to send a regular update to your manager or stakeholder.
Worried this might be too technical?
Valentinova points out that you don’t need to use code on a daily basis, you simply have to set up some of these scripts and then sit back and enjoy the benefits of proactive management.
There’s a detailed methodology on Valentinova’s blog (including a script download), guiding you through step-by-step to run an example script that checks for metadata changes. It breaks down simply as follows:
- Download and install Python.
- Download Valentinova’s example metadata script.
- Create an .xlsx input file which is simply a list of URLs and the page title and meta description you expect to see.
- Add your email address and login details and the input file name to the config file.
- Make sure your Gmail account will allow the script to access it (turn ‘less secure apps’ on).
- Use command line to download the necessary Python libraries (these allow for certain functionality, such as sending emails).
- Run the script.
After you’ve got to grips with this example, Valentinova recommends a number of other resources, including the creative commons manual Automate the Boring Stuff with Python and urllib2, a Python module that can be used to fetch URLs.
Spend time finding the solution not the problem
As Valentinova infectiously pointed out, there’s lots you can do with Python and it doesn’t have to be a daunting experiment. Ultimately, once you’ve mastered a few alerts, you can reduce the manual checks you have to do, and spend more time finding the solution rather than the problem
In the words of Valentinova, “automation is not a silver bullet, but SEO is a race” – Python is simply a way of getting a headstart.