Last active
September 6, 2023 05:25
-
-
Save mcnaveen/b57f5f776e8c07da54fdc36365d7fe99 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# URL of the Android Studio download page | |
URL="https://developer.android.com/studio" | |
# CSS selector to target the element | |
SELECTOR="#agree-button__studio_linux_bundle_download" | |
# Use curl to fetch the web page content and pipe it to grep | |
# -s: Silent mode (suppresses progress meter) | |
# -L: Follow redirects | |
# -o: Only print matched parts of the line | |
# -m 1: Stop after the first match | |
# -i: Case-insensitive search | |
href=$(curl -s -L "$URL" | grep -o -m 1 -iE "$SELECTOR.*href=['\"]([^'\"]+)['\"]" | sed -E "s/$SELECTOR.*href=['\"]([^'\"]+)['\"]/\1/") | |
if [ -n "$href" ]; then | |
echo "Scraped href: $href" | |
else | |
echo "Element with selector $SELECTOR not found." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment