Refactor web scraper code