Screen-scraping (which is essentially what you're doing here) should only be used as a last resort. Any change to the Web page you're fetching could potentially break your code. A much better way to solve your problem is to use a publicly-available API provided for third-party developers to request some data in a standard format. And it looks like Flickr provides just that: https://www.flickr.com/services/api/flickr.photos.search.html (note: I have no experience with this API. I simply found out that it exists after a quick google search).
If you fetch the proper API resource, you should get back a JSON object containing a list of URLs pointing directly to images. No more weird for()
loops, no more ugly (if magicNumber == 4)
or if (magicString == '\"src\"')
code. It should be pretty straightforward at that point to insert these images into your spreadsheet.