Skip to content

Instantly share code, notes, and snippets.

@hexaflexahexagon
Last active February 10, 2022 13:07
Show Gist options
  • Save hexaflexahexagon/3bda7cb1b974e10f4af90838b2b5bde0 to your computer and use it in GitHub Desktop.
Save hexaflexahexagon/3bda7cb1b974e10f4af90838b2b5bde0 to your computer and use it in GitHub Desktop.
# Try and google a prompt, then link the first result
#!/bin/bash
# Try and google a prompt, then link the first result
if [[ $1 == "" ]]; then
echo "Error: Please supply an argument to search for"
exit
fi
input=$( echo $1 | xxd -plain | tr -d '\n' | sed 's/\(..\)/%\1/g' )
output=$(curl -s 'https://www.google.com/search?q='$input'&source=hp&ei=Iy6dYZzbNdG0tAa1iaKwAg&iflsig=ALs-wAMAAAAAYZ08Mxhe9Zb7qEjDDCiUoPI1SDh5p3oY&ved=0ahUKEwjc-KuKiq_0AhVRGs0KHbWECCYQ4dUDCAk&uact=5&oq=curl&gs_lcp=Cgdnd3Mtd2l6EAMyCAgAEIAEELEDMgsIABCABBCxAxCDATIICAAQgAQQsQMyCAgAEIAEELEDMgsIABCABBCxAxCDATILCAAQgAQQsQMQgwEyCwgAEIAEELEDEIMBMgsIABCABBCxAxCDATIICAAQgAQQsQMyBQguEIAEOg4IABCPARDqAhCMAxDlAjoRCC4QgAQQsQMQgwEQxwEQ0QM6DgguEIAEELEDEMcBENEDOg4ILhCABBCxAxDHARCjAjoFCAAQgAQ6CAguELEDEIMBOhEILhCABBCxAxCDARDHARCjAjoLCC4QgAQQxwEQowI6CwguEIAEELEDEIMBOggILhCABBCxA1D2E1jGMWDSNGgEcAB4AIABTogBjQOSAQE3mAEAoAEBsAEK&sclient=gws-wiz' \
-H 'authority: www.google.com' \
-H 'cache-control: max-age=0' \
-H 'sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="96", "Google Chrome";v="96"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'sec-ch-ua-platform: "Windows"' \
-H 'upgrade-insecure-requests: 1' \
-H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' \
-H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' \
-H 'sec-ch-ua-full-version: "96.0.4664.45"' \
-H 'sec-ch-ua-arch: "x86"' \
-H 'sec-ch-ua-platform-version: "10.0.0"' \
-H 'sec-ch-ua-model: ""' \
-H 'x-client-data: CJe2yQEIo7bJAQjEtskBCKmdygEI49nKAQjq8ssBCOaEzAEItoXMAQjLicwBCMeLzAEIrI7MAQjXjswBCNuOzAEYqqnKARiMnssBGIeOzAE=' \
-H 'sec-fetch-site: same-origin' \
-H 'sec-fetch-mode: navigate' \
-H 'sec-fetch-user: ?1' \
-H 'sec-fetch-dest: document' \
-H 'accept-language: en-US,en;q=0.9' \
-H 'cookie: OTZ=6230154_72_76_104100_72_446760; NID=511=STZAax_bZYveRxo-qdizPIsijfNK4z64tiPZ1RtKFri1NdFgh8aXGX-H9UpNOMevO6iNs8ZjQ3wkdxwV5AqVeTBDIcnBKT_Fj3qcucI1m6gU5xpeU5G66-uzQTB_F681MeP6auhK5FBPddrCAxqjK11kUtChXiRE8bzUGgO1XBeAwKWwqrFMVz0g0Num69W7ANW2wMg6UrZT; 1P_JAR=2021-11-23-18; DV=Q14UTgpHllgscLaS0HzAkjkD1wHg1FfpwAAOteHUHAIAAAA' \
--compressed | egrep -o '<div class=\"yuRUbf\"><a href=\"https?:\/\/(www\.)?\S*' | head -n1)
cleanedOutput=$(echo $output | cut -c 30-1000 | sed 's/.$//')
echo "Your result is: $cleanedOutput"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment