怎么获取imdb,怎么才能获得imdb编号

首页 > 社会 > 作者:YD1662024-04-28 05:08:14

Python能抓取网页上的信息,当然bash也可以,今天小编就拿bash脚本来挖掘IMDb中的电影信息噢!!挺好玩的!!!

我们是做教育的,希望大家能够学到知识,这个一直是我们的初衷!!

怎么获取imdb,怎么才能获得imdb编号(1)

电影网站https://www.imdb.com,这个网站我自己登入上去看了看,确实可以登入,并不需要挂vpn,可惜的是英文。

因为代码太长了,我分屏了一下,大伙可以看行号码,不过我会把源码分享出去。

代码里用到了大量的sed和grep,这个sed我之前有分享,改天找个机会说说grep的使用。

怎么获取imdb,怎么才能获得imdb编号(2)

写好了运行一下吧,在脚本后面lawrence of arabia是电影的名字。

怎么获取imdb,怎么才能获得imdb编号(3)

你看吧!出来一系列的电影了!当然你的英文要好!!

怎么获取imdb,怎么才能获得imdb编号(4)

那我现在就分享一下代码吧!!

#!/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 "<title>" $tempout | sed 's/<[^>]*>//g;s/(more)//' grep --color=never -A2 '<h5>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 '<h1 class="findHeader">No ' $tempout)" if [ ! -z "$fail" ] ;then echo "Failed:no results foun for $1" exit 1 elif [ ! -z "$(grep '<h1 class="findHeader">Displaying' $tempout)" ] ;then grep --color=never '/title/tt' $tempout | \ sed 's/</\ </g' | \ grep -vE '(.png|.jpg|>[ ]*$)' |\ grep -A 1 "a href=" | \ grep -v '^--$' | \ sed 's/<a href="\/title\/tt//g;s/<\/a>//' | \ awk '(NR %2 ==1){title=$0} (NR %2 ==0){print title " " $0}' | \ sed 's/\/.*>/: /'|\ sort fi exit 0

大家可以复制下来运行一下,不懂的话直接私信小编,或者加群讨论!!一起学习一起进步!!!

我们是做教育的,希望大家能够学到知识,这个一直是我们的初衷!!

记住噢,加群讨论噢,不懂的可以问,也有人回答的。

栏目热文

文档排行

本站推荐

Copyright © 2018 - 2021 www.yd166.com., All Rights Reserved.