简述

网站链接
同学推荐的一个网站 (因为都是二次元党),顺便也爬了
因为不想费这么多心思在这,没加多线程,所以会爬的有点慢,给👴忍着

源码

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
import os,requests,bs4
n = input('请输入你想爬取多少页:')
try:
os.chdir(i)
download_path = os.path.join(os.getcwd(),'wallpaper\\')
print(download_path)
except:
os.chdir('C:\\Users\{}\\Desktop'.format(os.getlogin())) #默认保存文件夹,可以自己改
download_path = os.path.join(os.getcwd(),'wallpaper\\')
if not os.path.exists(download_path):
os.mkdir(download_path) #如果没有wallpaper文件夹,则自动创建
print('\n[+]当前下载目录为{}'.format(download_path))

def main(url,pic,down):
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0'}
r = requests.get(url,headers=headers)
html = bs4.BeautifulSoup(r.text,'html.parser')
src=html.findAll('a')
for i in src:
s = i.get('href')
try:
if s.split('/')[1] == 'pictures':
url = pic + s.split('/')[-1]
re = requests.get(url,headers=headers,stream=True)
soup = bs4.BeautifulSoup(re.text,'html.parser')
img = soup.findAll('a',attrs={'class':'download_icon'})
for j in img:
m = j.get("href")
print('\r[*]已找到图片链接{}\n'.format(m))
if m[-3] == 'p':
q = requests.get(down+m,headers=headers,stream=True)
filename = m.split('/')[-1]
with open(download_path+filename,'wb') as g:
for k in q.iter_content(10000):
g.write(k)
print('\r[+]爬取完成,图片名{}'.format(filename),end="")
else:
q = requests.get(down+m,headers=headers,stream=True)
filename = m.split('/')[-1]
with open(download_path+filename,'wb') as g:
for k in q.iter_content(10000):
g.write(k)
print('\r[+]爬取完成,图片名{}'.format(filename),end="")
except:
pass
for z in range(int(n)):
o = z
url = 'https://anime-pictures.net/pictures/view_posts/{}'.format(o)
pic = 'https://anime-pictures.net/pictures/view_post/'
down = 'https://anime-pictures.net'
main(url,pic,down)