-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscrape.py
More file actions
30 lines (27 loc) · 1.1 KB
/
scrape.py
File metadata and controls
30 lines (27 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python
# encoding: utf-8
from lxml import html
import requests
import random
import shutil
from string import ascii_lowercase, digits
def random_url():
url = ''.join(random.choice(digits + ascii_lowercase) for x in range(6))
return url
if __name__ == "__main__":
ids = []
#Change the number in range() to specify the number of images you want to download
for i in range(100):
ids.append(random_url())
page = requests.get("https://prnt.sc/" + ids[i], headers={'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:74.0) Gecko/20100101 Firefox/74.0"})
tree = html.fromstring(page.content)
image = ''.join(tree.xpath('//img[@id="screenshot-image"]/@src'))
if ("//st" not in image):
print(image)
r = requests.get(image, stream=True)
if r.status_code == 200:
with open( "output/" + ids[i] + ".png", "wb") as f:
r.raw.decode_content = True
shutil.copyfileobj(r.raw, f)
else:
print('Image not found. Moving on...')