#!/usr/bin/env bash # ============================================================================= # scraping.sh - Web Scraping Example # ============================================================================= # Demonstrates how to extract data from a web page using Shellnium. # This example scrapes a locally generated news listing page. # # Usage: # bash examples/scraping.sh [--headless] # ============================================================================= SCRIPT_DIR="$(cd -P "$(dirname "$(realpath "${BASH_SOURCE[0]:-${0}}")")" &>/dev/null && pwd)" source "${SCRIPT_DIR}/../lib/selenium.sh" _create_news_page() { local tmpfile tmpfile=$(mktemp /tmp/shellnium-scrape-XXXXXX.html) cat > "$tmpfile" << 'HTMLEOF' Tech News

Tech News

Bash scripting best practices for 2026
42 points | 15 comments
WebDriver protocol explained simply
38 points | 12 comments
Why shell automation is underrated
55 points | 23 comments
jq tips and tricks for JSON processing
31 points | 8 comments
Building a CI pipeline with shell scripts
27 points | 10 comments
Understanding ChromeDriver internals
44 points | 19 comments
Curl tricks every developer should know
61 points | 25 comments
Selenium vs Playwright vs Shellnium
89 points | 42 comments
How to test without external dependencies
33 points | 14 comments
Terminal-first development workflow
47 points | 18 comments
HTMLEOF echo "$tmpfile" } main() { local html_file html_file=$(_create_news_page) trap "rm -f '$html_file'" EXIT local url="file://${html_file}" echo "Navigating to ${url} ..." navigate_to "$url" # Extract the page title local title title=$(get_title) echo "Page title: ${title}" echo "---" # Find all story title links on the page local elements elements=$(find_elements 'css selector' '.titleline > a') local count=0 for element in $elements; do if [ "$count" -ge 10 ]; then break fi count=$((count + 1)) local text href text=$(get_text "$element") href=$(get_attribute "$element" 'href') echo "${count}. ${text}" echo " URL: ${href}" done echo "---" echo "Extracted ${count} stories." # Clean up delete_session } main