
分享一段源码挖掘IMDb电影信息
来源:
浏览:129
时间:2023-08-08
#!/bin/bash
#Date 2019-09-17
PATH=/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
titleurl="http://www.imdb.com/title/tt"
imdburl="http://www.imdb.com/find?s=tt&exact=true&ref_=fn_tt_ex&q="
tempout="/tmp/moviedata.$$"
summarize_film()
{
grep "" $tempout | sed 's/<[^>]*>//g;s/(more)//'
grep --color=never -A2 'Plot:' $tempout | tail -1 |
cut -d -f1 | fmt | sed 's/^/ /'
exit 0
}
trap "rm -f $tempout" 0 1 15
if [ $# -eq 0 ] ; then
echo "Usage:$0 {movie title | movie ID}" >&2
exit 1
fi
######
nodigits="$(echo $1 | sed 's/[[:digit:]]*//g')"
if [ $# -eq 1 -a -z "$nodigits" ] ;then
lynx -source "$titleurl$1/combined" > $tempout
summarize_film
exit 0
fi
########
fixedname="$(echo $@ | tr ' ' '+')"
url="$imdburl$fixedname"
lynx -source $imdburl$fixedname > $tempout
fail="$(grep --color --color=never 'No ' $tempout)"
if [ ! -z "$fail" ] ;then
echo "Failed:no results foun for $1"
exit 1
elif [ ! -z "$(grep 'Displaying' $tempout)" ] ;then
grep --color=never '/title/tt' $tempout |
sed 's/
[ ]*$)' |
grep -A 1 "a href=" |
grep -v '^--$' |
sed 's//: /'|
sort
fi
exit 0
| sed 's//: /'| sort fi exit 0
大家可以复制下来运行一下,不懂的话直接私信小编,或者加群讨论!!一起学习一起进步!!!
我们是做教育的,希望大家能够学到知识,这个一直是我们的初衷!!
记住噢,加群讨论噢,不懂的可以问,也有人回答的。


