-
Notifications
You must be signed in to change notification settings - Fork 0
/
img-from-pp163.py
63 lines (50 loc) · 1.45 KB
/
img-from-pp163.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
import os
import time
__author__ = 'lyle'
import requests
import re
from selenium import webdriver
index = 0
def downAllImage(url):
r = requests.get(url)
p = re.compile(r'data-lazyload-src="(.+?\.jpg)"')
base_path = os.path.join(os.path.expanduser('~'), "Documents/pp")
if not os.path.exists(base_path):
os.makedirs(base_path)
m = p.findall(r.text)
global index
for url in m:
print(url)
r = requests.get(url, stream=True)
filename = os.path.join(base_path, str(index)+".jpg")
with open(filename, 'wb') as fd:
for chunk in r.iter_content(1024):
fd.write(chunk)
index += 1
def downAllHref(web):
try:
es = web.find_elements_by_css_selector("a.img.js-anchor.etag.noul")
for e in es:
url = e.get_attribute("href")
downAllImage(url)
except():
print("error ")
def closeAD(web):
ad = web.find_element_by_css_selector("a.ztag.btn-close")
ad.click()
def nextPage(web):
next = web.find_element_by_css_selector("span.pgi.pgb.pgbright.iblock")
next.click()
def start():
web = webdriver.Chrome(os.path.join(os.path.expanduser('~'), "Documents/chromedriver"))
web.get("http://pp.163.com/pp/#p=10&c=-1&m=3&page=1")
time.sleep(3)
closeAD(web)
time.sleep(3)
while True:
downAllHref(web)
nextPage(web)
time.sleep(3)
web.quit()
if __name__ == "__main__":
start()