Don't use sockclose on the first one. Close the socket only after reaching the end of the html file (</html>).
if (</html> isin %temptext) { sockclose socketname }
Right now, your first example closes it after reading only one item, which isn't what you want. Your second example reads the second one because you used a sockread event inside of it, so it skips a line.