jack hace 1 año
padre
commit
c53fa90917
Se han modificado 1 ficheros con 21 adiciones y 17 borrados
  1. 21 17
      kaizty_spider.py

+ 21 - 17
kaizty_spider.py

@@ -2,10 +2,12 @@ import os.path
 import re
 import random
 import time
-
 import httpx
 
-url_key = 'UHh0dkRPOWwyV2R2V0ZFU3hMRFZaZz09.html?'
+url_keys = [
+    'L2lBQ200aE0vOVNmUGcydzhhT296Zz09',
+    'RFFRQXFIZEhNeDNaV2txWjRlMk5xdz09'
+]
 url_photos = '/photos/'
 base_url = 'https://www.kaizty.com/'
 url_page = 'page={}'
@@ -15,7 +17,7 @@ headers = {
 }
 
 
-def get_pages():
+def get_pages(url_key):
     title = ''
     all_img_list = []
 
@@ -54,7 +56,7 @@ def get_pages():
             error_times += 1
             continue
         all_img_list += img_list
-        # time.sleep(random.uniform(2, 3))
+        time.sleep(random.uniform(2, 3))
 
     return all_img_list, title
 
@@ -85,21 +87,23 @@ def get_imgs(all_img_list, title):
         print('正在保存图片: {}'.format(file_name))
         with open(title + "/" + file_name, "wb") as f:
             f.write(img.content)
-            # time.sleep(random.uniform(8, 10))
+            time.sleep(random.uniform(5, 8))
 
 
 if __name__ == '__main__':
-    all_img_list, title = get_pages()
-
-    while True:
-        try:
-            get_imgs(all_img_list, title)
-        except Exception as e:
-            print(e)
-            time.sleep(random.uniform(30, 40))
-            continue
-        else:
-            print("程序执行完成,退出循环")
-            break
+    for url_key in url_keys:
+        url_key = url_key + '.html?'
+        all_img_list, title = get_pages(url_key)
+
+        while True:
+            try:
+                get_imgs(all_img_list, title)
+            except Exception as e:
+                print(e)
+                time.sleep(random.uniform(30, 40))
+                continue
+            else:
+                print("图片保存完成,退出循环")
+                break
 
 print("done")