Python is a programming language that can help you uncover incredible SEO insights and save you time by automating time-consuming tasks. But for those who haven’t explored this side of search, it can be intimidating. In this episode of Whiteboard Friday, Britney Muller and a true python expert named Pumpkin offer an intro into a helpful tool that’s worth your time to learn.
Click on the whiteboard image above to open a high resolution version in a new tab!
Hey, Moz fans. Welcome to another edition of Whiteboard Friday. Today we’re talking all about introduction to Python, which is why I have a special co-host here. She is a ball python herself, total expert. Her name is Pumpkin, and she’s the best.
What is Python?
So what is Python? This has been in the industry a lot lately. There’s a lot of commotion that you should know how to use it or know how to talk about it. Python is an open source, object-oriented programming language that was created in 1991.
Simpler to use than R
Some fun facts about Python is it’s often compared to R, but it’s arguably more simple to use. The syntax just oftentimes feels more simple and common-sense, like when you’re new to programming.
Big companies use it
Huge companies use it. NASA, Google, tons of companies out there use it because it’s widely supported.
It’s open source
It is open source. So pretty cool. While we’re going through this Whiteboard Friday, I would love it if we would do a little Python programming today. So I’m just going to ask that you also visit this in another tab, python.org/downloads. Download the version for your computer and we’ll get back to that.
Why does Python matter?
So why should you care?
Automates time-consuming tasks
Python is incredibly powerful because it helps you automate time-consuming tasks. It can do these things at scale so that you can free up your time to work on higher-level thinking, to work on more strategy. It’s really, really exciting where these things are going.
Log file analysis
Some examples of that are things like log file analysis. Imagine if you could just set up an automated system with Python to alert you any time one of your primary pages wasn’t being crawled as frequently as it typically is. You can do all sorts of things. Let’s say Google crawls your robots.txt and it throws out a server error, which many of you know causes huge problems. It can alert you. You can set up scripts like that to do really comprehensive tasks.
Internal link analysis
Some other examples, internal link analysis, it can do a really great job of that.
Discover keyword opportunities
It can help you discover keyword opportunities by looking at bulk keyword data and identifying some really important indicators.
It’s really great for things like image optimization. It can auto tag and alt text images. It can do really powerful things there.
It can also scrape the websites that you’re working with to do really high volume tasks.
Google Search Console data analysis
It can also pull Google Search Console data and do analysis on those types of things.
I do have a list of all of the individuals within SEO who are currently doing really, really powerful things with Python. I highly suggest you check out some of Hamlet Batista’s recent scripts where he’s using Python to do all sorts of really cool SEO tasks.
How do you run Python?
What does this even look like? So you’ve hopefully downloaded Python as a programming language on your computer. But now you need to run it somewhere. Where does that live?
Set up a virtual environment using Terminal
So first you should be setting up a virtual environment. But for the purpose of these examples, I’m just going to ask that you pull up your terminal application.
It looks like this. You could also be running Python within something like Jupyter Notebook or Google Colab. But just pull up your terminal and let’s check and make sure that you’ve downloaded Python properly.
Check to make sure you’ve downloaded Python properly
So the first thing that you do is you open up the terminal and just type in “python –version.” You should see a readout of the version that you downloaded for your computer. That’s awesome.
Activate Python and perform basic tasks
So now we’re just going to activate Python and do some really basic tasks. So just type in “python” and hit Enter. You should hopefully see these three arrow things within your terminal. From here, you can do something like print (“Hello, World!”). So you enter it exactly like you see it here, hit Enter, and it will say “Hello, World!” which is pretty cool.
You can also do fun things like just basic math. You can add two numbers together using something like this. So these are individual lines. After you complete the print (sum), you’ll see the readout of the sum of those two numbers. You can randomly generate numbers. I realize these aren’t direct SEO applications, but these are the silly things that give you confidence to run programs like what Hamlet talks about.
Have fun — try creating a random number generator
So I highly suggest you just have fun, create a little random number generator, which is really cool. Mine is pulling random numbers from 0 to 100. You can do 0 to 10 or whatever you’d like. A fun fact, after you hit Enter and you see that random number, if you want to continue, using your up arrow will pull up the last command within your terminal.
It even goes back to these other ones. So that’s a really quick way to rerun something like a random number generator. You can just crank out a bunch of them if you want for some reason.
Automating different tasks
This is where you can start to get into really cool scripts as well for pulling URLs using Requests HTML. Then you can pull unique information from web pages.
You can pull at bulk tens of thousands of title tags within a URL list. You can pull things like H1s, canonicals, all sorts of things, and this makes it incredibly easy to do it at scale. One of my favorite ways to pull things from URLs is using xpath within Python.
This is a lot easier than it looks. So this might be an xpath for some websites, but websites are marked up differently. So when you’re trying to pull something from a particular site, you can right-click into Chrome Developer Tools. Within Chrome Developer Tools, you can right-click what it is that you’re trying to scrape with Python.
You just select “Copy xpath,” and it will give you the exact xpath for that website, which is kind of a fun trick if you’re getting into some of this stuff.
What are libraries? How do we make this stuff more and more powerful? Python is really strong on its own, but what makes it even stronger are these libraries or packages which are add-ons that do incredible things.
This is just a small percentage of libraries that can do things like data collection, cleaning, visualization, processing, and deployment. One of my favorite ways to get some of the more popular packages is just to download Anaconda, because it comes with all of these commonly used, most popular packages.
So it’s kind of a nice way to get all of it in one spot or at least most of them.
So you’ve kind of dipped your toes and you kind of understand what Python is and what people are using it for. Where can you learn more? How can you start? Well, Codecademy has a really great Python course, as well as Google, Kaggle, and even the Python.org website have some really great resources that you can check out.
This is a list of individuals I really admire in the SEO space, who are doing incredible work with Python and have all inspired me in different ways. So definitely keep an eye on what they are up to:
But yeah, Pumpkin and I have really enjoyed this, and we hope you did too. So thank you so much for joining us for this special edition of Whiteboard Friday. We will see you soon. Bye, guys.