说起爬虫,大家第一印象就是想到了python来做爬虫。其实,服务端语言好些都可以来实现这个东东。
在我们日常上网浏览网页的时候,经常会看到一些好看的图片,我们就希望把这些图片保存下载,或者用户用来做桌面壁纸,或者用来做设计的素材。
我们可以通过erlang 来实现这样一个简单的爬虫功能。下面就看看如何使用erlang来实现这样一个功能。
早在2011年的时候,我曾用erlang做过个简单的爬虫spider,只是爬取网页的a标签(<a href='xxxx'),在博客第一篇大概讲述了当时做的spider爬虫。
网上很多python有做爬取图片的,这里,我也拿这个开刀,用erlang做个爬取图片的简单功能。
-module(http). -compile(export_all). start() -> % application:start(inets), % application:start(crypto), % application:start(asn1), %一定要的 % application:start(public_key), %一定要的 % application:start(ssl), %一定要的 inets:start(), ssl:start(), % Res = httpc:request("https://gome.com.cn"), % Res = httpc:request(head, {"https://gome.com.cn", []}, [{ssl,[{verify,0}]}], []). % Res = httpc:request(get,{"https://www.jd.com",[]},[{autoredirect, true},{timeout, 10000}],[{sync, false}]), {ok,{_,_,Body}} = httpc:request("https://tieba.baidu.com/p/2460150866?red_tag=1460270922"), io:format("~ts",[unicode:characters_to_binary([Body])]), %匹配HTML标记的正则表达式 {match, Res} = re:run(Body, "<img",[{capture,first,list},global]), {match, Res1} = re:run(Body, "<img (.*?) src=\"(.+?)\".*?>",[{capture,first,list},global]), {match, Res} = re:run(Body, "<img src=\"([^\"]*?)\">",[{capture,first,list},global]).
https://www.cnblogs.com/abelsu/p/4540711.html
未写完 待续。。。。