Is it necessary to repeat this code over and over or can it dynamically change?

You can replace the changing part with a variable, and then loop over it. Similar to here:How to web scrape search results - #2 by ulrich