File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed
Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+
2+ import requests
3+ from bs4 import BeautifulSoup
4+ import time
5+ import random
6+
7+
8+ headers = {
9+ 'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36'
10+ }
11+
12+ def get_html (url ):
13+
14+ resp = requests .get (url = url , headers = headers )
15+ soup = BeautifulSoup (resp .text )
16+ return soup
17+
18+ def get_next_page (soup ):
19+ next_page = soup .find (class_ = 'previous-comment-page' )
20+ next_page_href = next_page .get ('href' )
21+ return f'http:{ next_page_href } '
22+
23+ def get_img_url (soup ):
24+ a_list = soup .find_all (class_ = 'view_img_link' )
25+ urls = []
26+ for a in a_list :
27+ href = 'http:' + a .get ('href' )
28+ urls .append (href )
29+ return urls
30+
31+ def save_image (urls ):
32+ for item in urls :
33+ name = item .split ('/' )[- 1 ]
34+ resp = requests .get (url = item , headers = headers )
35+ with open ('D:/xxoo/' + name , 'wb' ) as f :
36+ f .write (resp .content )
37+ time .sleep (random .randint (2 ,5 ))
38+
39+ if __name__ == "__main__" :
40+ url = 'http://jandan.net/girl' ;
41+ while True :
42+
43+ soup = get_html (url )
44+ urls = get_img_url (soup )
45+
46+ if (len (urls ) == 0 ):
47+ break
48+
49+ save_image (urls )
50+ url = get_next_page (soup )
51+
52+
You can’t perform that action at this time.
0 commit comments