font-weight: 400
انتشار: تیر 09، 1402
بروزرسانی: 31 خرداد 1404

font-weight: 400

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

Write a program that will extract <title> and meta description from a list of URLs.\xa0

You have three options for handling this:

  1. Remove the old code and paste in the new one.
  2. Create a new notebook.
  3. Insert a new cell.

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.

💡

Write a program for extracting just one column of data

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!

What you need to start programming right away\xa0

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

  • Copy the output from ChatGPT.
  • Paste the output to the new code cell in Google Colab.
  • Upload input files [1] [2] to Google Colab. For the purpose of this tutorial, use files provided by me [1] [2] In case you want to use your own files, ensure that:
    – Both files contain the URL field.
    – Both files contain URLs in the same format.
  • Run the code cell.

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

Writing your first Python program – “hello world”

To do this, in Google Colab click on “Insert” and then select “Code cell”.

Great work, ChatGPT, and Python!

Write a program that measures the speed of a website

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

  • It’s very easy to start. Creating your first Python program in it will take you just a couple of minutes (or a minute, if you’re fast).\xa0
  • You don’t need to install anything on your computer.\xa0
  • You can work on the same code with your friends or colleagues. Think of Google Docs but for Python programming. If you struggle with a specific program, you can ask your colleague for help.\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.

  • For each URL, it will extract the meta description and <title> tags.
  • Next, it will use the ChatGPT API to evaluate the <title> on a scale of 0-10, determining how likely it is to encourage people to click on the search result.
  • The program should also provide an explanation for each judgment.
  • The results should be saved in a CSV file named title_score.csv.

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.

  • Please write a Python program that extracts only the first column, which contains URLs, and saves it to a separate file named “urls_only.txt”. The program should handle cases where some data is missing for certain URLs.
  • After running the program, I would like it to give me a short report about the steps that the program has accomplished.

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!

P.S.

This guide is just a small part of my FREE ebook: Mastering ChatGPT for SEO.\xa0 Grab a copy!


منبع: https://www.onely.com/blog/python-for-seo/

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

Write a program that combines two files into one

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:

  • Copy the output from ChatGPT.
  • Paste the output into a new code cell in Google Colab.
  • Modify the code to include your OpenAI API key.

💬

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

Here’s the deal!

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

Important note:\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:

Wrapping up

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.

💬

💬

Write a Python program that downloads all the URLs in a sitemap, specifically and performs
the following tasks:
  • Save all the URLs in a file named “sitemap.txt”.
  • Visit all the URLs in the sitemap, up to a maximum of 100 URLs, and check their status codes. If a URL does not return a 200 OK status code, save it to a file named “broken_urls.csv”, which will contain two fields: the URL and its corresponding HTTP status code.

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:

Ideas for further improvement of the program:\xa0

  • Make sure that the data from both sources is homogeneous. Usually, Google Analytics data will present a relative URL while Google Search Console will always present the full URL. If this happens, the program will fail. In such cases, first instruct ChatGPT to add a “https://www” prefix to every URL from the ga_data.csv and then do the rest.\xa0
  • Ask ChatGPT to analyze the data more thoroughly. For instance, you may want to find URLs that visitors spend a lot of time on, but… with zero clicks from Google users,.\xa0 This will show you a list of URLs that are interesting for your users, but either aren’t indexed, or have some major ranking problems.\xa0

Using ChatGPT API

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

  • both present comma-separated values
  • If some data is missing in either table, please present it with an empty value
  • and make sure the program works fine with any columns
  • it should save the data to an external file named: combined_gsc_ga_data.csv

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:

  • Summarize your articles in bulk: You can create summaries or meta descriptions for many articles at once.
  • Check content quality in bulk: Ask ChatGPT to automatically go through a list of your articles to see how good your website’s content is.
  • Fix <title> tags in bulk: You can ask ChatGPT to go through a list of URLs, extract title tags and make ChatGPT optimize your website’s <title> tags better for more clicks and conversions.
  • Correct grammar in bulk: Fix grammar mistakes in multiple blog articles all at once.

Congratulations! You’ve just written your very first Python program!\xa0It printed “hello world” on the screen.\xa0

Write a program that downloads a sitemap

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

  • tool that scrapes a sitemap file and saves URLs with errors (404, 5xx) to a separate file.
  • scraper that extracts <title> and meta description tags from a list of URLs.
  • tool that connects to the PageSpeed Insights API to gather performance data about a given page.\xa0
  • program that performs basic manipulations with a CSV file.
  • program that combines data from Google Search Console and Google Analytics.
  • handy tool that uses the ChatGPT API and saves the results in a CSV file.
If you find the output quality isn’t great, there are several ways to improve it:

  • Refine the prompt: rewrite the prompt to specifically ask ChatGPT for ideas to enhance your titles.
  • Experiment with different ChatGPT models in the calls to ChatGPT API: in this case, the Python file generated by ChatGPT uses the text-davinci-002 model, which is based on GPT-2. You will get MUCH better results with GPT-3 or GPT-4 models.

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:

  • Ask ChatGPT to generate the program.\xa0
  • Copy the output generated by ChatGPT.
  • Insert a new code cell in Google Colab.
  • Upload the input file into Google Colab.\xa0
  • Paste the code and click on “Run”.\xa0

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!

Asking ChatGPT to explain Python code to you\xa0

As before, copy the code generated by ChatGPT and add a new code cell to your Google Colab notebook.\xa0