
بروزرسانی: 31 خرداد 1404
font-weight: 400
Make sure the explanation is written in simple words that anyone can understand.
Make sure the explanation is written in simple words that anyone can understand.
After uploading the file, the program should run smoothly, extracting the <title> and meta description values. As expected, the results will be saved in the “custom_extraction.csv” file:
Using Python we can easily write a program that will extract basic information (such as <title> and <meta> description from a list of pages).\xa0
You have three options for handling this:
If you encounter an error stating that the “openai module is not found”, you’ll need to install it. To do so, simply add the command !pip install openai before the ChatGPT output and run the cell again.
Please explain what the Python code below is meant to do
In case you don’t have the PageSpeed Insights API key, you can obtain it from: https://developers.google.com/speed/docs/insights/v5/get-started\xa0
As expected, ChatGPT generated this program for me:
If you’re new to Python and SEO, all the Python programs out there can seem overwhelming. But don’t worry, there’s an easy way to understand what a particular Python code does!
Next, copy and paste the code into a new cell in your Google Colab notebook.
💡
Python is an incredibly powerful programming language that’s not only quite easy to learn but also very helpful for SEO professionals. It can:
And the best part? You don’t need any prior programming experience! Let’s dive in and get started!
Once you paste the code, click the “Run” button.
💬
Write a program that will take a list of URLs from input.txt
and for each of the URLs it will get the PageSpeed Insights score.
Then save the results to the psi_api_output.csv file
with the most important metrics.
Important note:\xa0
Now, let’s dive into something more advanced. We’ll be using the PageSpeed Insights API to gather performance information about multiple URLs in bulk.\xa0
Please write a Python program that joins data from two files:
💡
Alternatively, if you’re pressed for time, or just not sure where exactly you should paste this, ask ChatGPT to generate the full program again, and you can replace the entire code so you can copy/paste it directly into the Google Colab Notebook:
Now, let’s explore some ways to enhance this program:
I suspect you already know what to do now. In case you hesitate:\xa0
If your sitemap is relatively small, in a couple of seconds Google Colab will notify you that it successfully finished the task:
For simplicity’s sake, let’s just add new cells to the same notebook.
Here’s a sample prompt:
Forget Excel; you can do it in Python. Here’s the prompt you can use:\xa0
Deal?\xa0
To do this, in Google Colab click on “Insert” and then select “Code cell”.
Great work, ChatGPT, and Python!
To run Python programs you need a Python environment. For the purpose of this tutorial, we will be using Google Colab. It’s awesome for three reasons:\xa0
1. gsc_data.csv
Here’s a sample prompt:\xa0
Write a Python program that will read a list of URLs from input.txt.
Think of some programs that can help you in your everyday SEO job and make use of chatGPT to help you write them!
Go ahead and paste the code you got from ChatGPT into a new Google Colab cell, then click the “Run” button.
You can then open the file to see if it was properly generated:\xa0
Alright, let’s move on to something more practical. How about we create a program that downloads all the URLs from a sitemap and saves them to a text file?
I have a CSV file named ‘gsc_data.csv’ that contains three columns: URL, Clicks, and CTR. Each column is separated by a comma.
Let’s do it!\xa0
You’ve already learned a lot!\xa0
Next, open Google Colab (it’s a special environment where you can run your Python programs) and select “New notebook” to create a fresh workspace.
Here’s my Python code:
💬
Once you enter the code and put your own API key in, click on the “Run” button again.\xa0
So, don’t hesitate to use this feature anytime you need a little help!
The program gave me the expected file with the results:\xa0
As expected, the program extracted 21 URLs from ‘gsc_data.csv’ and saved them to ‘urls_only.txt’. Below you can see the preview of this file:\xa0
Writing a program that will connect to Google PageSpeed API may seem complicated at first, but the best part is that the prompt is short and quite intuitive:
Then you do it in Excel, and it crashes. You try again and… it crashes.
Once you’ve got the code from ChatGPT, just as you did with the “Hello World” example, hit the “Copy code” button located at the top-right corner of the ChatGPT console.
I hope my instructions have helped you begin programming in Python. Now, it’s time for you to put what you’ve learned into action.
Another area where ChatGPT can be helpful is to generate a program that combines two files into one.
Follow these simple steps to get started:
💬
2. ga_data.csv
Write a Python program that will print: “hello world” on the display
But don’t worry we’ll take it step by step.\xa0
Make sure that the program handles any errors that may occur during execution. Write an explanation for each piece of code as a comment.
Now, in your Google Colab notebook, the main cell is already filled with the previous program.\xa0
❗
Have fun!
Now, practice! Let’s create a program using ChatGPT that:
In my case, I asked ChatGPT to explain one of the programs intended to extract the <title> and meta description tags that we generated earlier:
Now we’re entering a field where ChatGPT can generate different programs for every person. Some of them may work in the first run, some won’t. If something is wrong with the output don’t give up 🙂\xa0
When you try to use it, you’ll encounter an error saying the file doesn’t exist. To fix this, upload the “input.csv” file containing the URLs you want to scrape.
💬
💬
It’s unclear what logic ChatGPT follows while judging the clickability of pages. Unfortunately, it’s more of a black box, like Google.\xa0
💬
ChatGPT explained the cause of the error and provided steps to fix it. Note: I trimmed the screenshot for brevity.\xa0
This Python program perfectly joined the data, as shown in the screenshot below:
Click the “folder” icon from the menu and then upload the file. If you don’t want to use your own file, use my sample.\xa0
💬
ChatGPT quickly generated the Python program that can join two CSV files:\xa0
So no worries, we will make it work 🙂\xa0
based on the URL column
Now imagine you have a CSV file with lots of data, but you only want to extract a single column (for instance, a column with a list of URLs).
To ensure your success, you need to follow these guidelines:\xa0
Then copy the code provided by ChatGPT. You can do this by clicking on the: “Copy code” button.
Try:
\xa0
💡
In the prompt, you requested ChatGPT to download a full list of URLs and save them to a text file. To find this file in Google Colab, simply click the folder icon on the left, and here you’ll quickly spot the sitemap.txt file.
Write a Python program that:
ChatGPT quickly generated a Python program to accomplish the task:
With the power of the ChatGPT API, you can perform various tasks in bulk, making them more efficient and time-saving. Here’s how some of the examples mentioned earlier can be executed in bulk:
Congratulations! You’ve just written your very first Python program!\xa0It printed “hello world” on the screen.\xa0
This way, you can optimize your website more efficiently and effectively by understanding the performance of each <title> tag.
In this case, ChatGPT suggests replacing the get_pagespeed_insights_score function with a new, improved version. You can edit the code just like you would in a text editor, making sure to preserve the indentation (which is essential in Python).
Unfortunately, I encountered an error. Oh no!
Don’t worry, we’re sticking to a no-code approach for this tutorial.\xa0
Before you run it, please put your PageSpeed Insights API key into the code.
With ChatGPT, you can create this program in just a couple of minutes.
Making the output better
For instance, if your key is: “myKey43434343”, then the line should look like this: api_key = “myKey43434343”
After pasting the new code into Google Colab, it works perfectly!\xa0
We’ll create the following several handy tools:\xa0
If you find the output quality isn’t great, there are several ways to improve it:
Paste the copied code into the Google Colab cell (refer to the screenshot below for guidance) and hit the “Run” button:
Here’s a sample prompt:
Imagine you have two separate CSV files, one coming from Google Search Console, and the other coming from Google Analytics. Excel may quickly fail with larger volumes.\xa0
Using Python we can easily write a program that will extract basic information (such as <title> and <meta> description from a list of pages).\xa0
💬
To get started, request ChatGPT to generate a Python program for you:
Error: missing module
So let’s ask ChatGPT to help with the error:
As always, ChatGPT faced the challenge to generate such a program!\xa0
All programmers begin their journey in a similar fashion. They create a simple computer program designed to do one simple thing: display “Hello world” on the screen.
Type the following prompt into the chat:
In this guide, I’ll show you how to use Python programming even if you have no prior experience!\xa0
For an even better program, consider the following ideas:
Where is the generated file?
You already know the workflow:
Just ask ChatGPT to explain it to you. Here’s a sample prompt:
Make it more bullet-proof: Python programs can crash if for some reason they can’t visit certain URLs. To ensure smooth operation, ask ChatGPT to generate code that can handle errors. ChatGPT can give you new Python code that will alert you if something goes wrong but won’t break the tool. Here’s a sample: Write a program that will extract <title> and meta description from a list of URLs.\xa0
If you want to have more predictable results, use ChatGPT custom training techniques. As always, make sure it works in your niche!
As before, copy the code generated by ChatGPT and add a new code cell to your Google Colab notebook.\xa0