-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzendriverpy.py
More file actions
67 lines (51 loc) · 2.33 KB
/
zendriverpy.py
File metadata and controls
67 lines (51 loc) · 2.33 KB
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
67
import asyncio
import curl
import zendriver as zd
from fake_useragent import UserAgent
import os
async def main():
ua = UserAgent()
browser = await zd.start()
with open("links.txt") as f:
for x in f:
page = await browser.get(x.strip())
await asyncio.sleep(2)
elements = await page.select_all("a.album__main")
print(f"Found {len(elements)} categories")
for element in elements:
Title = await element.get("title")
folder_name = "".join(c for c in Title if c.isalnum() or c in " _-").strip()
folder_name = folder_name.replace(" ", "_")
os.makedirs(folder_name, exist_ok=True)
await element.click()
await asyncio.sleep(2)
Referer = page.url
images = await page.select_all("img")
print(f"Found {len(images)} images in category")
for idx, img in enumerate(images):
if img.get("data-path") is None:
print(f"Image {idx} has no data-path attribute, skipping.")
continue
src = img.get("data-path")
if src and src.startswith("/yolo66/"):
# download hell starts here
print(f"Image {idx}: src={src!r}")
url = "https://photo.yupoo.com" + src
headers = {
"User-Agent": ua.random,
"Referer": Referer,
"Accept": "image/avif,image/webp,image/apng,image/*,*/*;q=0.8"
}
response = requests.get(url, headers=headers, stream=True)
filename = os.path.join(folder_name, f"image{idx}.jpg")
if response.status_code == 200:
with open(filename, "wb") as f:
for chunk in response.iter_content(1024):
f.write(chunk)
print("Download completed: {filename}")
else:
print(f"Failed to download, status code: {response.status_code}")
else:
print(f"Image {idx} has no valid data-path attribute, skipping.")
if __name__ == "__main__":
asyncio.run(main())