Created
July 13, 2023 18:40
-
-
Save mcattani/6e0133587c90fd76409c863342e3eae4 to your computer and use it in GitHub Desktop.
Descarga de imágenes del sitio LightShot utilizando un patrón conocido (dos letras-cuatro números)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! python3 | |
# prnt.sc_downloader.py - | |
# Descarga de imágenes del sitio LightShot utilizando un patrón conocido (dos letras-cuatro números) | |
import requests, os, bs4, random, time | |
url = 'https://prnt.sc/' # URL de base | |
os.makedirs('imagenes', exist_ok=True) | |
headers = [{'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0'}, | |
{'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'}, | |
{'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393'}, | |
{'user-agent':'Mozilla/5.0 (iPad; CPU OS 8_4_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12H321 Safari/600.1.4'}] | |
#print(random.choice(headers)) | |
def download_image(url_letter, url_number): | |
# Descargamos la página | |
randomHead = random.choice(headers) | |
print('Descargando página https://prnt.sc/%s%s...' % (url_letter, url_number)) | |
res = requests.get( 'https://prnt.sc/%s%s...' % (url_letter, url_number), headers=randomHead) | |
try: | |
res.raise_for_status() | |
except Exception as exs: | |
print('Hubo un problema: %s' % (exs)) | |
soup=bs4.BeautifulSoup(res.text, 'html.parser') | |
#Buscamos la URL de la imagen | |
imagen = soup.find_all(class_="no-click screenshot-image") | |
#print(imagen[0]) | |
if imagen == []: | |
print('No se pudo encontrar la imágen') | |
else: | |
#imagen = 'https:' + imagen[0].get('src') | |
imagen = imagen[0].get('src') | |
if imagen.startswith("//"): | |
print('Imágen removida') | |
return | |
#Bajamos la imagen | |
print('Bajando imagen %s...' % (imagen)) | |
res = requests.get(imagen, headers=randomHead) | |
try: | |
res.raise_for_status() | |
except Exception as exs: | |
print('Hubo un problema: %s' % (exs)) | |
imageFile=open(os.path.join('imagenes', os.path.basename(imagen)), 'wb') | |
for chunk in res.iter_content(10000): | |
imageFile.write(chunk) | |
imageFile.close() | |
#img_bajadas = 1 | |
for x in range(6000,7000): | |
download_image('aa',x) | |
time.sleep(random.uniform(0.1,1.5)) | |
#print(f'Bajadas:{img_bajadas}') | |
#img_bajadas += 1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment