-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.py
More file actions
52 lines (39 loc) · 1.21 KB
/
parser.py
File metadata and controls
52 lines (39 loc) · 1.21 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from random import randint
from bs4 import BeautifulSoup
from threading import Thread
import cloudscraper
import requests
import os
def create_name_page():
name = ""
for i in range(5):
name += chr(randint(97, 122))
name += str(randint(0, 9))
return name
def get_html(name):
page = "https://prnt.sc/" + name
print(page)
scraper = cloudscraper.create_scraper()
return scraper.get(page).text
def parse_html_page(html):
soup = BeautifulSoup(html, "html.parser")
string = soup.find_all("img", alt="Lightshot screenshot")
return string[0]["src"]
def save_image(url, name_file):
response = requests.get(url).iter_content()
try:
with open(f"{os.getcwd()}/images/{name_file}.jpg", "wb") as file:
for i in response:
file.write(i)
except:
os.mkdir(os.getcwd() + "/images/")
with open(f"{os.getcwd()}/images/{name_file}.jpg", "wb") as file:
for i in response:
file.write(i)
def main():
while True:
random_name = create_name_page()
save_image(parse_html_page(get_html(random_name)), random_name)
for i in range(4):
thread = Thread(target=main(), args=(i,))
thread.start()