http=require'socket.http'
--iterator1 = io.lines("uniq.txt")
start_topic=16367
end_topic=16367
urlbit1="http://www.volvo300mania.com/uk/forum/viewtopic.php?t="
urlbit2="&start="
urlbit3="&view=print"
for topic=start_topic,end_topic do
--for topic in iterator1 do
old_url_text_length=0
saved_pages=""
for start_page=0, 500, 15 do
url=urlbit1..topic..urlbit2..start_page..urlbit3
url_text, statusCode, headers, statusText = http.request(url)
if statusCode ~=200 then
print("Topic "..topic.." does not exist.")
break
end
worked_OK, url_text_length=pcall(string.len,url_text)
if not worked_OK then print("Error getting length of text for topic: "..topic) break
elseif start_page==0 then print("New topic: "..topic)
elseif url_text_length==old_url_text_length then
print("Reached end of this topic.")
break
end
old_url_text_length=url_text_length
newfile=topic.."_"..start_page
wget_string="wget -E -H -k -r -l 1 -w 2 --random-wait --tries=1 ".."\""..url.."\""
--print(wget_string)
if pcall(os.execute, wget_string)
then
print("Saved: "..newfile)
else
print("Error saving: "..newfile)
end
end
end