GET_URL=$1
DO_LINKS=${2:-"0"}
WIDTH=${3:-"56"}

DST_PAGE=/tmp/surfer.tmp
DST_LINK=/tmp/surfer.tmp.lnk

rm -f $DST_PAGE
rm -f $DST_LINK

[ -z "$GET_URL" ] && exit 1

lynx -dump -width=$WIDTH -hiddenlinks=ignore "$GET_URL" | \
awk '{
	if(links == 1 && link_section == 1) {
		gsub("^[ 0-9]*\. ", "")
		if(length($0) > 0 && index($0,"http://") == 1)
			print $0 >>dst
	} else {
		if(match($0,"References") || match($0,"Verweise"))
			link_section = 1
		else {
			gsub("\[[0-9]*\]", "")
			print $0
		}
	}
}' links=$DO_LINKS dst=$DST_LINK 2>/dev/null | \
sed -e 's/\[[0-9a-zA-Z_?&=.]* //g' -e 's/\[[0-9a-zA-Z_?&=.]*$//g' >$DST_PAGE 2>/dev/null

exit 0
