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:
- Libraries: ready-made collections of tools.
- Functions: blocks of code that do one thing.
- 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:
- Go to
colab.research.google.com - Sign in with Gmail
- File → New notebook
- Import libraries
- 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
- NumPy - numerical calculations.
- Pandas - data manipulation.
- Matplotlib - graphs and charts.
- Scikit-learn - machine learning.
- TensorFlow - AI and neural networks.
- Flask / Django - web frameworks.
Resources
CTAs
- "Get started?" form
- "Book my session"



