refactor duplication in web scraping functions