Created
June 25, 2020 22:16
-
-
Save himynameisdave/5c02fcac75c18dd3ebc1d58cb67825a8 to your computer and use it in GitHub Desktop.
Bash script to scrape Google for the current USD-to-CAD exchange rate
This file contains hidden or 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 | |
# Variables (feel free to edit these) | |
FROM_CURRENCY='usd' | |
TO_CURRENCY='cad' | |
# Constants | |
USER_AGENT="User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36" | |
SEARCH_URL="https://www.google.com/search?hl=en&q=$FROM_CURRENCY%20to%20$TO_CURRENCY" | |
# Command | |
OUTPUT=$(curl -s -H "$USER_AGENT" "$SEARCH_URL" | grep -Eo 'data-exchange-rate="[^\"]+"' | grep -Eo '"([^"\\]|\\.)*"') | |
echo $OUTPUT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment