Reference library
Automation & scripting
CLI tools, scheduled jobs, filesystem tasks, and glue scripts that save time.
Extract All Links from Any Website in Python
Scrape a webpage and extract all absolute HTTP/HTTPS links using requests and regex.
import requests
import re
from urllib.parse import urljoin
def extract_links(url):
try:
response = requests.get(url)
response.raise_for_status()
html = response.text
# Find all href attributes in anchor tags
pattern = r'href=["\'](.*?)["\']'
raw_links = re.findall(p…
How to Generate a QR Code in Python
Generate a QR code image from a URL string using the qrcode library and save it as a PNG file.
import qrcode
# Data to encode
data = "https://www.example.com"
# Create QR code instance
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
# Add data to QR code
qr.add_data(data)
qr.make(fit=True)
# Create an image from the QR code
img = qr.…
Browse by section
Each section groups closely related Python snippets.
Automation & scripting — Python code examples
What you will find here
This page collects automation & scripting snippets — short, copy-ready Python you can paste into our free online IDE and run without installing anything. Each sample includes a plain-English explanation and the full source code.
Samples vs tutorials and challenges
Samples are quick reference — one concept per page. For step-by-step teaching, use our Python tutorials. To test yourself, try quizzes or coding challenges. Clean up style with the Python formatter.