import requests from bs4 import BeautifulSoup import os url =…
- User
import requests from bs4 import BeautifulSoup import os
url = 'https://wiki.rage.mp/index.php?title=Vehicles' # Replace with the URL of the webpage you want to scrape response = requests.get(url) soup = BeautifulSoup(response.content, 'html.parser')
def download_image(url: str, output_folder: str, filename: str) -> None: response = requests.get(url) if response.status_code == 200: with open(os.path.join(output_folder, filename), 'wb') as f: f.write(response.content) print(f'Downloaded {filename}') else: print(f'Error downloading {url}: {response.status_code}')
output_folder = 'output1080p' if not os.path.exists(output_folder): os.makedirs(output_folder)
image_count = 0 for div in soup.find_all('div', {'class': 'thumb'}): img = div.find('img') if img is not None: src = img['src'] response = requests.get('https://wiki.rage.mp/' + src) # Append the src attribute to the base url if response.status_code == 200: image_count += 1 gallery_text_div = div.find_next_sibling('div', {'class': 'gallerytext'}) code_tag = gallery_text_div.find('code') if code_tag is not None: filename = f'{code_tag.text}.png' file_url = f"https://wiki.rage.mp/index.php?title=File:{code_tag.text}.png" file_page_response = requests.get(file_url) file_page_soup = BeautifulSoup(file_page_response.content, 'html.parser') file_href = file_page_soup.find('div', {'class': 'fullMedia'}).find('a', {'class': 'internal'}).get('href') download_image('https://wiki.rage.mp/' + file_href, output_folder, filename) else: filename = f'image{image_count}.png' download_image(response.url, output_folder, filename) else: print(f'Error downloading {src}: {response.status_code}')
print(f'Total Images downloaded: {image_count}')
for some reason the first one works without any issue the second one doesn't work could you edit the code so it works for both
- Assistant
I understand the issue. The problem is with different formats of image source URLs on the wiki page. To fix it, I'll make some modifications to the image scraping part of the code. Here is the modified version:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.