Rebol - 1̶6̶4̶ 134
Parses the html using the parse
sub-language of Rebol. Checks the first 19 pages (ignoring errors).
Thanks to @rgchris for improvements!
s: 0 repeat n 20[parse read join http://stackoverflow.com/questions?sort=featured&page= n[any[thru{>+}copy x to{<}(s: s + load x)]]]s
Test
>> s: 0 repeat n 20[parse read join http://stackoverflow.com/questions?sort=featured&page= n[any[thru{>+}copy x to{<}(s: s + load x)]]]s
== 24150
Explanation
Rebol ignores whitespace, hence you can put it all on one line like that if you choose. PARSE takes two inputs, and the first argument (read join ...
) is fairly self-explanatory. But here are some comments on the parse dialect instructions, in a more traditional indentation:
s: 0
repeat n 20 [
parse read join http://stackoverflow.com/questions?sort=featured&page= n [
;-- match the enclosed pattern ANY (zero or more number of times)
any [
;-- seek the match position up THRU (and including) the string >+
thru {>+}
;-- copy contents at the current position up TO (but not including) <
copy x to {<}
;-- (Basically, run some non-dialected Rebol if this match point is reached)
(s: s + load x)
]
]
]
;-- evaluator returns last value, we want the value in S
;-- (not the result of PARSE, that's a boolean on whether the end of input was reached)
s