-
Notifications
You must be signed in to change notification settings - Fork 0
/
ppscrape.py
executable file
·74 lines (56 loc) · 2.27 KB
/
ppscrape.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
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
import os
import requests
from bs4 import BeautifulSoup
from urllib.parse import urlparse, urljoin
import pyfiglet
from termcolor import colored
import pyperclip
# Create ASCII art
ascii_art = pyfiglet.figlet_format("porn pics", font="slant")
# Add color to the ASCII art
colored_ascii_art = colored(ascii_art, color="cyan")
# Print the colored ASCII art
print(colored_ascii_art)
def download_images(url):
try:
# Send a GET request to the URL
response = requests.get(url)
response.raise_for_status()
except requests.exceptions.RequestException as e:
print(f"Failed to retrieve page content: {e}")
return
# Parse the HTML content of the page
soup = BeautifulSoup(response.content, 'html.parser')
# Extract the title of the page to create a folder
title = soup.title.string.strip()
folder_name = os.path.join("/home/adam178/.pornpics", title.replace(" - PornPics.com", ''))
# Create a folder if it doesn't exist
os.makedirs(folder_name, exist_ok=True)
# Find all elements with class 'rel-link'
rel_links = soup.find_all(class_='rel-link')
# Track downloaded images
downloaded_images = set(os.listdir(folder_name))
# Download each image
for rel_link in rel_links:
img_url = rel_link['href']
img_url = urljoin(url, img_url)
if img_url.endswith(('.jpg', '.jpeg', '.png')):
img_name = os.path.basename(img_url)
if img_name in downloaded_images:
print(f"Skipping {img_name}, already downloaded.")
continue
try:
img_response = requests.get(img_url)
img_response.raise_for_status()
with open(os.path.join(folder_name, img_name), 'wb') as img_file:
img_file.write(img_response.content)
print(f"Downloaded: {img_name}")
except requests.exceptions.RequestException as e:
print(f"Failed to download image {img_name}: {e}")
print("\033[31mAuto Getting link from the clipboard\033[0m")
# Main URL of the page to scrape
url = pyperclip.paste()
print("URL: ", url)
# Call the function to download images
download_images(url)