'Python strings split and assign to variable

I am trying to get google images's url using python. I used to google_images_download module to it. I have get code in stack overflow.

from io import BytesIO, TextIOWrapper

from google_images_download import google_images_download
import sys


old_stdout = sys.stdout
sys.stdout = TextIOWrapper(BytesIO(), sys.stdout.encoding)


response = google_images_download.googleimagesdownload()

arguments = {
    "keywords": "stackoverflow",
    "limit": 3,
    "print_urls": True,
    "size": "large",
}
paths = response.download(arguments)

sys.stdout.seek(0)
output = sys.stdout.read()

sys.stdout.close()
sys.stdout = old_stdout

for line in output.split('\n'):
    if line.startswith("Image URL:"):
        s = line.replace("Image URL: ", "")
        print(s)

print(s) in last line is print three links of images. I want assign that three links to different variables. How can I do it?



Solution 1:[1]

Just create a list of URLs:

url_list = []
for line in output.split('\n'):
    if line.startswith("Image URL:"):
        s = line.replace("Image URL: ", "")
        url_list.append(s)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SamR