- 论坛徽章:
- 27
|
会当凌绝顶聪 发表于 2014-10-27 10:22
继续!等着下文呢 ! - -module(sohu_tv).
- -compile([export_all]).
- -define(USER_AGENT_HEADER,{"User-Agent","Mozilla/5.0 (Windows NT 6.0) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.68 Safari/534.24"}).
- -define(LOG_FILE,?MODULE ++ ".log").
- -define(LINKS_FILE,"links.log").
- go()->
- inets:start(),
- case httpc:request(get,{"http://tv.sohu.com/hotdrama/?d",[?USER_AGENT_HEADER]},[{autoredirect,false}],[]) of
- {ok, {{_Version, StatusCode, _ReasonPhrase}, _, _Body}} when StatusCode==301; StatusCode==302 ->
- StatusCode;
- {ok, {{_Version, _StatusCode, _ReasonPhrase}, _Headers, Body}} ->
- parse_links(Body);
- {error,Reason} ->
- [Reason]
- end.
- parse_links(Body) ->
- Regexp = "href\s*?=\s*?\"([^\"]+?)\"",
- case re:run(Body,Regexp,[{capture,all,list},global]) of
- {match,Matches} ->
- [file:write_file(?LINKS_FILE,Link ++ "\r\n",[append]) || [_Match,Link] <- Matches];
- nomatch ->
- []
- end.
- log_timestamp() ->
- {{Year,Mon,Day},{Hour,Min,Sec}} = erlang:localtime(),
- io_lib:fwrite("~w/~2.2.0w/~2.2.0w ~2.2.0w:~2.2.0w:~2.2.0w",[Year,Mon,Day,Hour,Min,Sec]).
-
-
复制代码 |
|