import requests URL components that remain constant baseurl =…
- User
import requests
URL components that remain constant
base_url = "https://streetviewpixels-pa.googleapis.com/v1/tile" params = { "cb_client": "apiv3", "panoid": "PE_T7MEVqiLN24OVdKE8cA", "output": "tile", "zoom": 5, "nbt": 1, "fover": 2 }
Headers for the request
headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:130.0) Gecko/20100101 Firefox/130.0", "Accept": "image/avif,image/webp,image/png,image/svg+xml,image/;q=0.8,/*;q=0.5", "Accept-Language": "ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3", "Sec-Fetch-Dest": "image", "Sec-Fetch-Mode": "cors", "Sec-Fetch-Site": "cross-site", "Priority": "u=5, i" }
Loop over x and y from 0 to 15
for x in range(16): for y in range(16): # Update the parameters for each loop iteration params["x"] = x params["y"] = y
code# Make the GET request response = requests.get(base_url, headers=headers, params=params) # Check if the request was successful if response.status_code == 200: # Save the image to a file file_name = f"tile_x{x}_y{y}.png" with open(file_name, 'wb') as f: f.write(response.content) print(f"Downloaded {file_name}") else: print(f"Failed to download tile with x={x} and y={y}, status code {response.status_code}")Как сохранять в папку images
- Assistant
To save the downloaded images to a specific folder, such as
images, you need to ensure that the folder exists and then specify the folder path when defining the file name for saving. Here's how you can modify your script to save the images in theimagesfolder:- Create the
imagesfolder if it does not exist.
- Create the