Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
974 B
11
Indexable
Never
import requests
from bs4 import BeautifulSoup
from urllib.parse import urljoin


def get_contact_us_url(url):
    # Send a GET request to the specified URL
    response = requests.get(url)

    # Parse the HTML content using BeautifulSoup
    soup = BeautifulSoup(response.content, 'html.parser')

    # Find the "Contact Us" page link
    contact_us_link = None
    anchors = soup.find_all('a')
    for anchor in anchors:
        if 'contact' in anchor.text.lower():
            contact_us_link = anchor.get('href')
            break

    if contact_us_link is not None:
        # Get the absolute URL of the contact us page
        contact_us_url = urljoin(url, contact_us_link)
        return contact_us_url

    else:
        return None


# Example usage
website_url = 'https://alpha.com/'
contact_us_url = get_contact_us_url(website_url)
if contact_us_url:
    print("Contact Us URL:", contact_us_url)
else:
    print("Contact Us page link not found on", website_url)