Here’s a quick beginner’s guide for those who want to start using ChatGPT to create working Python scripts.


Why This Guide?

If you’re new to Python and unsure where to begin, this tutorial will guide you on utilizing ChatGPT to generate a script for scraping web page headings. All you’ll need is ChatGPT and Google Colab.

Once you get the hang of this, you’ll be able to create scripts that do things out of thin air! Which eventually leads to building web apps. It’s a great skill to learn. Especially for SEO!


1. Setting Up Google Colab

Google Colab is a handy environment for testing scripts. If you’re unfamiliar:

  1. Search for ‘Google Colab
  2. Select the first result
  3. Create a new notebook (It’ll look similar to this screenshot)

New Google Collab

Now, let’s move to ChatGPT to create our prompt.


2. Generating the Perfect Prompt for ChatGPT

Here’s how I structured my prompt for the best results:

  1. Specify the environment (e.g., Python script for Google Colab)
  2. Provide clear instructions
  3. Ask for the complete code

Note: asking for the full code can sometimes yield better results. ChatGPT can be stingy sometimes!


Here is the exact prompt I use in the video:

“Hello, ChatGPT. Please create a Python script for Google Collab that does the following:
1. User provides a URL
2. Crawl the page (you may need to use a user agent to bypass crawling restrictions)
3. Output all HTML headings separated by line breaks

Please provide the full code.”


3. Running Your Script

Once ChatGPT provides the script, copy and paste it into Google Colab. Hit ‘Run’ and ensure you’ve installed any necessary libraries, like BeautifulSoup. Libraries in Python are like plugins that enhance script capabilities.

Run Python Script

For this script, after running, you’ll be prompted to input a URL. It will then scrape the headings, beneficial for SEO purposes, which is my professional forte.


4. The Power of ChatGPT for Non-Coders

Even if you’re unfamiliar with Python, tools like ChatGPT can empower you to create impressive scripts.

In just three months, I’ve crafted various scripts and even built web apps without in-depth coding knowledge.

Start experimenting, and you’ll soon discover the possibilities.


5. Troubleshooting Tips

Scripts don’t always run smoothly. If you encounter issues:

  1. Copy your broken code and or error messages
  2. Feed to ChatGPT for troubleshooting help
  3. Provide the error message or the faulty code for guidance

ChatGPT fixes broken code

Troubleshooting is part of the learning curve, so don’t be discouraged!


Want to Learn More?

Subscribe to my newsletter for weekly AI-powered SEO strategies. You can also connect with me on LinkedIn for more updates.

Recommended Posts