APFerrer
Back to blog
Quick tipsTrucos rápidos

Quick tricks: URL tracking

APFerrerOctober 20, 202415 min
Lead

Today: See the outbound links from a URL using Python and Google Colab

Quick tricks: URL tracking

Today: See the outbound links from a URL using Python and Google Colab

Why you need this:

  • Security: spot PHP injections redirecting to fraudulent sites.
  • SEO: catch broken links and links to low-quality domains.
  • Control: keep your domain safe.

There's a hack where someone injects a malicious file (usually PHP) into your web root.

What is Python?

Language created in 1991 by Guido van Rossum. Accessible, flexible. Three core building blocks:

  1. Libraries: ready-made collections of tools.
  2. Functions: blocks of code that do one thing.
  3. Variables: reusable data.

Basic example

import requests

def fetch_page(url):
    response = requests.get(url)
    return response.text

content = fetch_page("https://www.example.com")
print(content)

What is Google Colab?

Free Google tool for running Python in your browser.

Why it's useful:

  • No local setup needed
  • Free CPU/GPU
  • Real-time collaboration
  • Saves to Drive
  • Pre-installed libraries (Pandas, NumPy, TensorFlow)

You don't install anything on your computer. All you need is a Google account.

How to use: tracking internal links

Steps:

  1. Go to colab.research.google.com
  2. Sign in with Gmail
  3. File → New notebook
  4. Import libraries
  5. Define crawler functions

Full code

import requests
from bs4 import BeautifulSoup
from urllib.parse import urlparse, urljoin

domain = "apferrer.com"
visited = set()
internal = set()

def get_links(url):
    links = set()
    try:
        response = requests.get(url)
        soup = BeautifulSoup(response.text, "html.parser")
        for link in soup.find_all('a', href=True):
            link_url = link['href']
            absolute_url = urljoin(url, link_url)
            link_domain = urlparse(absolute_url).netloc
            if not any(x in absolute_url for x in ['mailto:', 'tel:', '#']) and domain in link_domain:
                internal.add(absolute_url)
                links.add(absolute_url)
        return links
    except Exception as e:
        print(f"Error getting links from {url}: {e}")
        return set()

def crawl_site(url):
    if url not in visited:
        visited.add(url)
        links = get_links(url)
        for link in links:
            if link not in visited:
                crawl_site(link)

crawl_site("https://apferrer.com")
print(f"Total internal: {len(internal)}")
print(internal)

That's it

I said it would be quick and practical.

Key Python libraries

  1. NumPy - numerical calculations.
  2. Pandas - data manipulation.
  3. Matplotlib - graphs and charts.
  4. Scikit-learn - machine learning.
  5. TensorFlow - AI and neural networks.
  6. Flask / Django - web frameworks.

Resources

CTAs

  • "Get started?" form
  • "Book my session"
AF
APFerrer
APFerrer · Consultora en datos y procesos
Author's note

Does it apply to your company? Tell me in 30 minutes and we'll see what fits.

Book 30 min