Skip to content

Instantly share code, notes, and snippets.

@rodrigo-x
Last active October 11, 2023 06:31
Show Gist options
  • Save rodrigo-x/e441a244f8852a600b39453c07a6759d to your computer and use it in GitHub Desktop.
Save rodrigo-x/e441a244f8852a600b39453c07a6759d to your computer and use it in GitHub Desktop.
raspadinha no meuguia..
#!/usr/bin/env bash
######################################
# Uso: [canal] [seletor de tag HTML]
# Ex: ./raspagem.sh "GRD" "h2"
######################################
check_dependencies() {
if ! command -v curl &>/dev/null; then
echo "Erro: O comando 'curl' não está instalado. Por favor, instale-o."
exit 1
fi
if ! command -v htmlq &>/dev/null; then
echo "Erro: O comando 'htmlq' não está instalado. Por favor, instale-o."
exit 1
fi
}
get_html() {
local url="$1"
local curl_output
curl_output=$(curl -s "$url")
if [ -z "$curl_output" ]; then
echo "Erro ao obter a página da web."
exit 1
fi
echo "$curl_output"
}
extract_tag() {
local html="$1"
local tag_selector="$2"
local hour_selector="$3"
local html_tag
html_tag=$(htmlq --text "$hour_selector, $tag_selector" <<< "$html")
if [ -z "$html_tag" ]; then
echo "Digite a HTML tag corretamente."
exit 1
fi
echo -e "$html_tag"
}
main() {
check_dependencies
local url="https://meuguia.tv/programacao/canal/$1"
local tag_selector="$2"
local hour_selector=".lileft"
if [ -z "$url" ] || [ -z "$tag_selector" ]; then
echo "Uso: $0 [canal] [seletor de tag HTML]"
exit 1
fi
local html
html=$(get_html "$url")
local html_tag
html_tag=$(extract_tag "$html" "$tag_selector" "$hour_selector")
echo "$html_tag"
}
main "$1" "$2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment