Create a script that searches for websites selling containers in south africa and have it save these to a Sitelist.txt file. Then it should check the whois data for any similarities and output these to a commons.txt file. Then it should check which of these have the contact person as info@(whatever the site is) output these to InfoAT.txt Then it should search everywhere that can be searched even through pdf texts if possible for the following number 10223266025 it's a bank account number - output these results to bank.txt The point of this script is to hunt scammers. If you have any other logic that might help please add it in.
import requests
from bs4 import BeautifulSoup
import whois
import re
from urllib.parse import urlsplit
from datetime import datetime
import pdfquery
from pdfquery import PDFQuery
from fpdf import FPDF
from pywhois import Whois
from pytz import timezone
from colorama import init, Fore, Style
from urllib3.exceptions import TimeoutError, ConnectionError
from requests.exceptions import ProxyError, RequestException
from time import sleep
import os

# Initialize colorama
init(autoreset=True)

class WebsiteAnalyzer:
    def __init__(self, url):
        self.url = url
        self.domain = urlsplit(url).netloc

    def get_whois_data(self):
        try:
            return whois.whois(self.domain)
        except Exception as e:
            print(f"Error getting WHOIS data for {self.domain}: {e}")
            return None

    def check_contact_info(self):
        try:
            response = requests.get(self.url, timeout=10)
            response.raise_for_status()
            soup = BeautifulSoup(response.text, 'html.parser')
            return soup.find('a', string=re.compile(r'info')) or soup.find('a', string=re.compile(r'contact'))
        except (TimeoutError, ConnectionError, RequestException) as e:
            print(f"Error checking contact info for {self.domain}: {e}")
            return None

    def search_pdf(self):
        try:
            pdfs = []
            url = f"https://www.google.com/search?q=site:{self.domain}+filetype:pdf"
            response = requests.get(url, timeout=10)
            response.raise_for_status()
            soup = BeautifulSoup(response.text, 'html.parser')
            for link in soup.find_all('a'):
                if link.get('href') and link.get('href').endswith('.pdf'):
                    pdfs.append(link.get('href'))
            return pdfs
        except (TimeoutError, ConnectionError, RequestException) as e:
            print(f"Error searching PDFs for {self.domain}: {e}")
            return []

    def search_bank_account(self, pdfs):
        bank_account = '10223266025'
        for pdf in pdfs:
            try:
                with open(pdf, 'rb') as f:
                    pdf_data = f.read()
                query = PDFQuery(pdf_data)
                for page in query.pages:
                    text = page.text
                    if bank_account in text:
                        with open('bank.txt', 'a') as f:
                            f.write(pdf + '\n')
            except Exception as e:
                print(f"Error searching bank account in PDFs for {self.domain}: {e}")

    def find_name_and_contact(self):
        try:
            response = requests.get(self.url, timeout=10)
            response.raise_for_status()
            soup = BeautifulSoup(response.text, 'html.parser')
            names = []
            for tag in soup.find_all(['h1', 'h2', 'h3', 'h4', 'h5', 'h6']):
                if tag.text:
                    names.append(tag.text.strip())
            contacts = []
            for link in soup.find_all('a'):
                if link.get('href') and link.get('href').startswith('tel'):
                    contacts.append(link.get('href').split(':')[1])
            return names, contacts
        except (TimeoutError, ConnectionError, RequestException) as e:
            print(f"Error finding name and contact for {self.domain}: {e}")
            return [], []

    def find_registrant_info(self):
        try:
            whois_data = self.get_whois_data()
            if whois_data:
                registrant_name = whois_data['name']
                registrant_email = whois_data['email']
                return registrant_name, registrant_email
            else:
                return None, None
        except Exception as e:
            print(f"Error finding registrant info for {self.domain}: {e}")
            return None, None

    def find_social_media_links(self):
        try:
            response = requests.get(self.url, timeout=10)
            response.raise_for_status()
            soup = BeautifulSoup(response.text, 'html.parser')
            social_media_links = []
            for link in soup.find_all('a'):
                if link.get('href') and any(social_media in link.get('href') for social_media in ['facebook', 'twitter', 'instagram', 'linkedin']):
                    social_media_links.append(link.get('href'))
            return social_media_links
        except (TimeoutError, ConnectionError, RequestException) as e:
            print(f"Error finding social media links for {self.domain}: {e}")
            return []

    def find_email_addresses(self):
        try:
            response = requests.get(self.url, timeout=10)
            response.raise_for_status()
            soup = BeautifulSoup(response.text, 'html.parser')
            email_addresses = []
            for link in soup.find_all('a'):
                if link.get('href') and link.get('href').startswith('mailto'):
                    email_addresses.append(link.get('href').split(':')[1])
            return email_addresses
        except (TimeoutError, ConnectionError, RequestException) as e:
            print(f"Error finding email addresses for {self.domain}: {e}")
            return []

def search_websites():
    try:
        websites = []
        url = "https://www.google.com/search?q=containers+south+africa+online"
        response = requests.get(url, timeout=10)
        response.raise_for_status()
        soup = BeautifulSoup(response.text, 'html.parser')
        for link in soup.find_all('a'):
            if link.get('href') and link.get('href').startswith('http'):
                websites.append(link.get('href'))
        return websites
    except (TimeoutError, ConnectionError, RequestException) as e:
        print(f"Error searching websites: {e}")
        return []

def save_websites(websites, filename):
    with open(filename, 'w') as f:
        for website in websites:
            f.write(website + '\n')

def main():
    websites = search_websites()
    save_websites(websites, 'Sitelist.txt')

    for website in websites:
        analyzer = WebsiteAnalyzer(website)
        whois_data = analyzer.get_whois_data()
        if whois_data:
            with open('commons.txt', 'a') as f:
                f.write(f"{website} + Name: {whois_data['name']} + Email: {whois_data['email']}\n")

        contact_info = analyzer.check_contact_info()
        if contact_info:
            with open('InfoAT.txt', 'a') as f:
                f.write(f"{website}\n")

        pdfs = analyzer.search_pdf()
        analyzer.search_bank_account(pdfs)

        names, contacts = analyzer.find_name_and_contact()
        for name in names:
            for contact in contacts:
                with open('name_contact.txt', 'a') as f:
                    f.write(f"{name} + {contact}\n")

        registrant_name, registrant_email = analyzer.find_registrant_info()
        if registrant_name and registrant_email:
            with open('registrant_info.txt', 'a') as f:
                f.write(f"{registrant_name} + {registrant_email}\n")

        social_media_links = analyzer.find_social_media_links()
        for link in social_media_links:
            with open('social_media_links.txt', 'a') as f:
                f.write(f"{link}\n")

        email_addresses = analyzer.find_email_addresses()
        for email in email_addresses:
            with open('email_addresses.txt', 'a') as f:
                f.write(f"{email}\n")

if __name__ == "__main__":
    main()