Skip to content

Instantly share code, notes, and snippets.

@matheusfillipe
Last active April 19, 2024 21:05
Show Gist options
  • Save matheusfillipe/b90710104ecb57bed83438104c1b77ad to your computer and use it in GitHub Desktop.
Save matheusfillipe/b90710104ecb57bed83438104c1b77ad to your computer and use it in GitHub Desktop.
Metacritic scrapper with bash and htmlq
#!/usr/bin/env bash
query="Final%20Fantasy"
user_agent='user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36'
results=$(curl "https://www.metacritic.com/search/$query/?page=1&category=3" -H "$user_agent" | htmlq 'div.c-pageSiteSearch-results a' -a href | xargs printf "https://www.metacritic.com%s\n" % '_')
item () {
name="$1"
selector="$2"
body="$3"
echo "$body" | htmlq "$selector" -t | tr -d '\n' | xargs -I '_' printf "%s: %s\n" "$name" '_'
}
for result in $results; do
echo "URL: $result"
body="$(curl --silent "$result" -H "$user_agent")"
item "Title" 'div.c-productHero_title h1' "$body"
item "Platform" 'div.c-productHero_score-container div.c-ProductHeroGamePlatformInfo title' "$body"
item "Release Date" 'div.c-productHero_score-container div.g-text-xsmall span.u-text-uppercase' "$body"
item "Meta Score" 'div.c-productScoreInfo_scoreNumber div.c-siteReviewScore_background-critic_medium span' "$body"
item "User Score" 'div.c-productScoreInfo_scoreNumber div.c-siteReviewScore_background-user span' "$body"
echo "--------------------------------------------------------------------------------"
echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment