Design concern with custom tpl.php
It's bad practice from a general development point of view (look up "separation of concerns")
It can break caching, or render it useless/pointless.
One bit of code should do one thing, and do it in a such a way that is testable. 


In my opinion, your logic for scraping should be in its own class, a class that does nothing but scrape. Then your preprocess function should make use of that class, and prepare the variables for the template.

You don't have to do any of this, of course, it's up to you what best practices you want to follow. If you're new to development, take it from me that modularising your code now will probably save you a lot of time when you come back to in 2 years and something doesn't work.