Skip to content

Instantly share code, notes, and snippets.

@NTCoding
Created August 19, 2012 09:28
Show Gist options
  • Select an option

  • Save NTCoding/3393952 to your computer and use it in GitHub Desktop.

Select an option

Save NTCoding/3393952 to your computer and use it in GitHub Desktop.
-module(scraper).
-compile(export_all).
start() ->
scrape(1).
scrape(X) ->
inets:start(),
Url = "http://www.ebuyer.com/284697-b525-hd-webcam-usb-in-960-000842",
{ok, {_, _, Body}} = httpc:request(get, {Url, []}, [], []),
Price = parse_price_from(Body),
io:format("Latest price of webcam is ~p~n", [Price]),
case X > 20 of
true -> exit("CPU is about to die");
false -> scrape(X + 1)
end.
parse_price_from(Html) ->
{match, [{_, _}, {Start, _}]} = re:run(Html, "<span property=\"v:price\">(.*)</span>"),
Price = string:substr(Html, Start + 1, 5).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment