当前位置:首页 > 技术文章 > 正文内容

分享一段源码挖掘IMDb电影信息

arlanguage2个月前 (03-18)技术文章10

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

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

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

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

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

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

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

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

#!/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 '<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 -A 1 "a href=" | \
 grep -v '^--</div><script nonce="mB6Bir83jW2OLkWtGSEbz" type="text/javascript" src="https://lf-dw.toutiaostatic.com/obj/toutiao-duanwai/toutiao/toutiao_web_pc/common/syl_page.b67e737d.js" crossorigin="anonymous"></script><script nonce="mB6Bir83jW2OLkWtGSEbz" type="text/javascript" src="https://lf-dw.toutiaostatic.com/obj/toutiao-duanwai/toutiao/toutiao_web_pc/common/htmlparser2.7ef956fe.js" crossorigin="anonymous"></script><script nonce="mB6Bir83jW2OLkWtGSEbz" type="text/javascript" src="https://lf-dw.toutiaostatic.com/obj/toutiao-duanwai/toutiao/toutiao_web_pc/common/tt_pc_bricks.8b365a8a.js" crossorigin="anonymous"></script><script nonce="mB6Bir83jW2OLkWtGSEbz" type="text/javascript" src="https://lf-dw.toutiaostatic.com/obj/toutiao-duanwai/toutiao/toutiao_web_pc/common/collect.9c3f3aed.js" crossorigin="anonymous"></script><script nonce="mB6Bir83jW2OLkWtGSEbz" type="text/javascript" src="https://lf-dw.toutiaostatic.com/obj/toutiao-duanwai/toutiao/toutiao_web_pc/common/react.ab24d615.js" crossorigin="anonymous"></script><script nonce="mB6Bir83jW2OLkWtGSEbz" type="text/javascript" src="https://lf-dw.toutiaostatic.com/obj/toutiao-duanwai/toutiao/toutiao_web_pc/common/runtime.432dd451.js" crossorigin="anonymous"></script><script nonce="mB6Bir83jW2OLkWtGSEbz" type="text/javascript" src="https://lf-dw.toutiaostatic.com/obj/toutiao-duanwai/toutiao/toutiao_web_pc/common/vendor.7fb6799a.js" crossorigin="anonymous"></script><script nonce="mB6Bir83jW2OLkWtGSEbz" type="text/javascript" src="https://lf-dw.toutiaostatic.com/obj/toutiao-duanwai/toutiao/toutiao_web_pc/pages/newsDetail/index.d1dc73b8.js" crossorigin="anonymous"></script></body></html> | \
 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
</pre><p>大家可以复制下来运行一下,不懂的话直接私信小编,或者加群讨论!!一起学习一起进步!!!</p><p>我们是做教育的,希望大家能够学到知识,这个一直是我们的初衷!!</p><p>记住噢,加群讨论噢,不懂的可以问,也有人回答的。</p></div>                </div>
                                <div class="copynotice">
                    <div data-qrurl="http://www.arlanguage.com/post/3392.html" class="tpureqr"></div>                    <div class="copynoticetxt">
                    <p>扫描二维码推送至手机访问。</p><p>版权声明:本文由<strong>AR编程网</strong>发布,如需转载请注明出处。</p>                    <p>本文链接:<a href="http://www.arlanguage.com/post/3392.html">http://www.arlanguage.com/post/3392.html</a></p>                    </div>
                </div>
                                                <div class="tags">
                    标签:                    <a href='http://www.arlanguage.com/tags-342.html' title='电影源代码中字在线观看'>电影源代码中字在线观看</a>                </div>
                            
        <div class="sharebox">
            <div class="label">分享给朋友:</div>
            <div class="sharebtn">
                <div class="sharing" data-initialized="true">
                    <a href="#" class="share-icon icon-weibo">微博</a>
<a href="#" class="share-icon icon-qq">QQ</a>
<a href="#" class="share-icon icon-wechat">微信</a>
<a href="#" class="share-icon icon-douban">豆瓣</a>
<a href="#" class="share-icon icon-qzone">QQ空间</a>
<a href="#" class="share-icon icon-linkedin">领英</a>                </div>
            </div>
        </div>
        </div>
        <div class="pages">
            <a href="http://www.arlanguage.com/category-1.html" class="backlist">返回列表</a>
            <p>上一篇:<a href="http://www.arlanguage.com/post/3391.html" class="single-prev">图解--《源代码》</a></p>
            <p>下一篇:<a href="http://www.arlanguage.com/post/3393.html" class="single-next">穿越时空的心灵之旅:电影《源代码》中的科幻和哲学探索</a></p>
        </div>
    </div>
<div class="block">
	<div class="posttitle"><h4>“分享一段源码挖掘IMDb电影信息” 的相关文章</h4></div>
	<div class="relatecon">
<div class="relate"><div class="relateinfo">
						<h3><a href="http://www.arlanguage.com/post/154.html" title="Linux下如何用nginx+ffmpeg搭建流媒体服务器">Linux下如何用nginx+ffmpeg搭建流媒体服务器</a></h3>
						<p>安装ffmpeg安装过程略安装完成后,检查是否安装成功。比如我这里采用向pili推流的方式,将本地的一个mp4视频推流到七牛pili。ffmpeg -re -i /tmp/ffmpeg_test.mp4 -vcodec copy -acodec copy -f flv "rtmp://pil...</p></div>
				</div><div class="relate"><div class="relateinfo">
						<h3><a href="http://www.arlanguage.com/post/197.html" title="如何让Nginx更安全? nginx怎么保证高可用">如何让Nginx更安全? nginx怎么保证高可用</a></h3>
						<p>网络安全的重要性不言而喻。那么小伙伴们有没有在日常使用 Nginx 的时候,特意去关注下它的安全配置呢?今天松哥和小伙伴们讨论一下如何安全的使用 Nginx,给大伙几个建议。一 使用最新版建议使用最新版的 Nginx,对于已经部署的 Nginx,要及时更新到最新版本,以确保所有已知的安全漏洞都已修补...</p></div>
				</div><div class="relate"><div class="relateinfo">
						<h3><a href="http://www.arlanguage.com/post/206.html" title="Linux 网络延迟排查方法 linux延迟10秒">Linux 网络延迟排查方法 linux延迟10秒</a></h3>
						<p>在 Linux 服务器中,可以通过内核调优、DPDK 以及 XDP 等多种方式提高服务器的抗攻击能力,降低 DDoS 对正常服务的影响。在应用程序中,可以使用各级缓存、WAF、CDN 等来缓解 DDoS 对应用程序的影响。但是需要注意的是,如果 DDoS 流量已经到达 Linux 服务器,那么即使应...</p></div>
				</div><div class="relate"><div class="relateinfo">
						<h3><a href="http://www.arlanguage.com/post/213.html" title="C# 实现高并发 Web 应用的性能优化秘籍">C# 实现高并发 Web 应用的性能优化秘籍</a></h3>
						<p>在现代的互联网应用中,尤其是大型 Web 应用,性能和可扩展性成为了核心竞争力。随着用户访问量和数据量的增大,高并发处理成为了系统稳定性和响应速度的关键因素。无论是电商平台、社交网站还是 SaaS 应用,如何应对海量用户的同时访问,确保系统高效运转,已经成为了技术人员面临的重要挑战。C# 和 ASP...</p></div>
				</div><div class="relate"><div class="relateinfo">
						<h3><a href="http://www.arlanguage.com/post/234.html" title="Linux Shell">Linux Shell</a></h3>
						<p>基本语法第一行第一行必须是 #!/bin/sh。它不是注释,#!/bin/sh 是对shell的声明,说明你所用的是那种类型的shell及其路径所在如果没有声明,则脚本将在默认的shell中执行,默认shell是由用户所在的系统定义为执行shell脚本的shell如果脚本被编写为在Kornshell...</p></div>
				</div><div class="relate"><div class="relateinfo">
						<h3><a href="http://www.arlanguage.com/post/263.html" title="Java学习路线总结">Java学习路线总结</a></h3>
						<p>本文整理了java开发的学习路线和相关的学习资源,非常适合零基础入门java的同学,希望大家在学习的时候,能够节省时间。良心推荐!第一阶段:Java基础重点知识点:数据类型、核心语法、面向对象、数组、集合、IO流、String/StringBuffer/StringBuilder、线程、并发、反射、...</p></div>
				</div>	</div>
</div>
</div>
<div class="sidebar fixed">
    
<dl id="divCatalog" class="sidebox">
    <dt class="sidetitle">网站分类</dt>    <dd>
        				<ul><li><a title="技术文章" href="http://www.arlanguage.com/category-1.html">技术文章</a></li>
</ul>
		    </dd>
</dl><dl id="divTags" class="sidebox">
    <dt class="sidetitle">标签列表</dt>    <dd>
        				<ul><li><a title="nginx debug" href="http://www.arlanguage.com/tags-69.html">nginx debug<span class="tag-count"> (31)</span></a></li>
<li><a title="nginx 替换" href="http://www.arlanguage.com/tags-76.html">nginx 替换<span class="tag-count"> (29)</span></a></li>
<li><a title="nginx别名" href="http://www.arlanguage.com/tags-78.html">nginx别名<span class="tag-count"> (33)</span></a></li>
<li><a title="nginx httpd" href="http://www.arlanguage.com/tags-82.html">nginx httpd<span class="tag-count"> (31)</span></a></li>
<li><a title="ubuntu nginx 卸载" href="http://www.arlanguage.com/tags-99.html">ubuntu nginx 卸载<span class="tag-count"> (30)</span></a></li>
<li><a title="windows nginx 负载" href="http://www.arlanguage.com/tags-112.html">windows nginx 负载<span class="tag-count"> (29)</span></a></li>
<li><a title="nginx asp.net" href="http://www.arlanguage.com/tags-130.html">nginx asp.net<span class="tag-count"> (33)</span></a></li>
<li><a title="zookeeper nginx" href="http://www.arlanguage.com/tags-158.html">zookeeper nginx<span class="tag-count"> (43)</span></a></li>
<li><a title="nginx博客" href="http://www.arlanguage.com/tags-159.html">nginx博客<span class="tag-count"> (31)</span></a></li>
<li><a title="nginx   ffmpeg" href="http://www.arlanguage.com/tags-162.html">nginx   ffmpeg<span class="tag-count"> (51)</span></a></li>
<li><a title="nginx 网盘" href="http://www.arlanguage.com/tags-189.html">nginx 网盘<span class="tag-count"> (33)</span></a></li>
<li><a title="nginx 分析工具" href="http://www.arlanguage.com/tags-220.html">nginx 分析工具<span class="tag-count"> (35)</span></a></li>
<li><a title="phpstudy nginx" href="http://www.arlanguage.com/tags-240.html">phpstudy nginx<span class="tag-count"> (30)</span></a></li>
<li><a title="目前最好的编程语言" href="http://www.arlanguage.com/tags-315.html">目前最好的编程语言<span class="tag-count"> (32)</span></a></li>
<li><a title="tan角度对照表" href="http://www.arlanguage.com/tags-316.html">tan角度对照表<span class="tag-count"> (34)</span></a></li>
<li><a title="三角函数记忆顺口溜" href="http://www.arlanguage.com/tags-317.html">三角函数记忆顺口溜<span class="tag-count"> (31)</span></a></li>
<li><a title="三角函数值常用表" href="http://www.arlanguage.com/tags-318.html">三角函数值常用表<span class="tag-count"> (32)</span></a></li>
<li><a title="函数的定义域有几种类型" href="http://www.arlanguage.com/tags-348.html">函数的定义域有几种类型<span class="tag-count"> (36)</span></a></li>
<li><a title="函数的定义域和值域练习题" href="http://www.arlanguage.com/tags-349.html">函数的定义域和值域练习题<span class="tag-count"> (32)</span></a></li>
<li><a title="高中八种基本函数图像" href="http://www.arlanguage.com/tags-350.html">高中八种基本函数图像<span class="tag-count"> (35)</span></a></li>
<li><a title="java文档" href="http://www.arlanguage.com/tags-354.html">java文档<span class="tag-count"> (31)</span></a></li>
<li><a title="苹果javascript能关闭吗" href="http://www.arlanguage.com/tags-361.html">苹果javascript能关闭吗<span class="tag-count"> (30)</span></a></li>
<li><a title="对数函数与指数函数的互换公式" href="http://www.arlanguage.com/tags-378.html">对数函数与指数函数的互换公式<span class="tag-count"> (33)</span></a></li>
<li><a title="导数反推原函数公式" href="http://www.arlanguage.com/tags-379.html">导数反推原函数公式<span class="tag-count"> (32)</span></a></li>
<li><a title="c语言编译器核心编辑" href="http://www.arlanguage.com/tags-395.html">c语言编译器核心编辑<span class="tag-count"> (31)</span></a></li>
</ul>
		    </dd>
</dl><dl id="divComments" class="sidebox">
    <dt class="sidetitle">最新留言</dt>    <dd>
        				<ul></ul>
		    </dd>
</dl></div>                            </div>
        </div>
    </div>
</div>
<div class="footer">
	<div class="fademask"></div>
    <div class="wrap">
        <h3><a href="https://beian.miit.gov.cn/" target="_blank">滇ICP备2024046894号-3</a></h3>
        <!--<h4>Powered By <a href="https://www.zblogcn.com/" title="Z-BlogPHP 1.7.3 Build 173295" target="_blank" rel="noopener norefferrer">Z-BlogPHP</a>. Theme by <a href="https://www.toyean.com/" target="_blank" title="拓源网">TOYEAN</a>.</h4>-->
        
    </div>
</div>
<div class="edgebar">
<a href="javascript:$.translatePage();" target="_self" id="zh_language" class="lang"></a>
<script>var cookieDomain = "http://www.arlanguage.com/";</script>
<script src="http://www.arlanguage.com/zb_users/theme/tpure/plugin/lang/zh_language.js"></script>
<a href="javascript:;" target="_self" class="setnight"></a></div></body>
</html><!--72.98 ms , 11 queries , 4121kb memory , 0 error-->