-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
67 lines (54 loc) · 2.05 KB
/
main.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import os
from typing import Counter
import requests
from bs4 import BeautifulSoup
from random import randint
def getPagesCount():
pages = []
resp = requests.get(f'https://anime-pictures.net/pictures/view_posts/0?search_tag=loli&order_by=date&ldate=0&lang=ru')
soup = BeautifulSoup(resp.text, 'lxml')
for page_link in soup.find_all('a', class_ = 'disable_on_small'):
try:
lpart = page_link.get('href')[1:].split('/')[2]
pages.append(int(lpart.partition('?')[0]))
except IndexError:
pass
return max(pages)
def randomLoliPicture():
global count
count = 0
os.system("mkdir loli")
c = getPagesCount()
for page in range(0,c):
resp = requests.get(f'https://anime-pictures.net/pictures/view_posts/{page}?search_tag=loli&order_by=date&ldate=0&lang=ru')
soup = BeautifulSoup(resp.text, 'lxml')
ret = []
for link in soup.find_all('a'):
tmp = link.get('href')[1:].split('/')
try:
if tmp[0] == 'pictures' and tmp[1] == 'view_post':
ret.append('/'.join(tmp))
except IndexError:
pass
try:
for i in range(0, len(ret)):
link = f'https://anime-pictures.net/{ret[i]}'
try:
resp = requests.get(link)
except:
raise Exception('Subpage Error')
soup = BeautifulSoup(resp.text, 'lxml')
try:
count+=1
imgtag = soup.find_all('img', {"id": "big_preview"}).pop()
imglink = f"http:{imgtag.get('src')}"
print(count, ")" , imglink)
filename = imglink.split('/')[-1]
r = requests.get(imglink, allow_redirects=True)
open(f"./loli/{filename}", 'wb').write(r.content)
print("Успешно скачано!")
except:
pass
except:
pass
randomLoliPicture()