Created
August 4, 2021 17:35
-
-
Save yanissi/d2d6345561b8851a139703752be8d847 to your computer and use it in GitHub Desktop.
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
import requests | |
import pandas as pd | |
import urllib.request | |
from slugify import slugify | |
df = pd.read_csv("clippings.csv") | |
token = "9HGDNG5-50E40Y9-MRTE5HC-HRWHPPB" | |
for clipping in df.itertuples(): | |
try: | |
clippingUrl = clipping[1] | |
print(f"Trying {clippingUrl} Full Page") | |
fileName = slugify(clippingUrl).replace("-html","").replace("www-","").replace("https-","") | |
result = requests.get(f"https://shot.screenshotapi.net/screenshot?token={token}&url={clippingUrl}&full_page=1&output=json&no_cookie_banners=true&block_ads=true") | |
urllib.request.urlretrieve(result.json()['screenshot'], f"{fileName}.png") | |
print(clippingUrl + " Done") | |
except: | |
try: | |
print(f"Trying {clippingUrl} 3000 height") | |
fileName = slugify(clippingUrl).replace("-html","").replace("www-","").replace("https-","") | |
result = requests.get(f"https://shot.screenshotapi.net/screenshot?token={token}&url={clippingUrl}&height=3000&output=json&no_cookie_banners=true&block_ads=true") | |
urllib.request.urlretrieve(result.json()['screenshot'], f"{fileName}.png") | |
print(clippingUrl + " Done") | |
except: | |
try: | |
print(f"Trying {clippingUrl} 1000 height") | |
fileName = slugify(clipping).replace("-html","").replace("www-","").replace("https-","") | |
result = requests.get(f"https://shot.screenshotapi.net/screenshot?token={token}&url={clippingUrl}&height=1000&output=json&no_cookie_banners=true&block_ads=true") | |
urllib.request.urlretrieve(result.json()['screenshot'], f"{fileName}.png") | |
print(clippingUrl + " Done") | |
except: | |
print(f"Failed: {clippingUrl}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment