![]() |
|
My book searching function (libgen, no api) - Printable Version +- Sinisterly (https://sinister.li) +-- Forum: Coding (https://sinister.li/Forum-Coding) +--- Forum: Coding (https://sinister.li/Forum-Coding--71) +--- Thread: My book searching function (libgen, no api) (/Thread-My-book-searching-function-libgen-no-api) |
My book searching function (libgen, no api) - sunjester - 01-09-2019 Code: function __booksearch
{
bs=urlencode "${1}" &> /dev/null
curl -s "http://libgen.io/search.php?req="$bs"&lg_topic=libgen&open=0&view=simple&res=999&phrase=1&column=def" >books
id=$(grep -Eio "id[=][0-9]{7}>(.+?)" books|cut -d '=' -f 2|cut -d '>' -f 1)
title=$(grep -Eio "id[=][0-9]{7}>(.+?)" books|cut -d '>' -f 2|cut -d '<' -f 1)
rm books
echo "[$id] $title"
}
alias booksearch='__booksearch'usage: Code: (xenial)root@localhost:~/# booksearch "red team field manual"
[1160277] Rtfm: Red Team Field Manualpastebin link: https://pastebin.com/raw/mgkA5hxK may also need this function Code: #https://stackoverflow.com/questions/296536/how-to-urlencode-data-for-curl-command
urlencode() {
local data
if [[ $# != 1 ]]; then
echo "Usage: $0 string-to-urlencode"
return 1
fi
data="$(curl -s -o /dev/null -w %{url_effective} --get --data-urlencode "$1" "")"
if [[ $? != 3 ]]; then
echo "Unexpected error" 1>&2
return 2
fi
echo "${data##/?}"
return 0
}RE: My book searching function (libgen, no api) - kyda - 02-12-2019 This is amazing! Nice coding! Found what I need. Thanks! RE: My book searching function (libgen, no api) - mothered - 02-12-2019 You contribute some very beneficial pieces of coding, and this certainly Is no exception. Well done. |