import requests

# Define the URL
url = "https://www.screener.in/user/company/export/526347/"

# Define headers
headers = {
    "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
    "accept-language": "en-US,en;q=0.9",
    "cache-control": "no-cache",
    "content-type": "application/x-www-form-urlencoded",
    "cookie": "csrftoken=lHCsvs4IMAw0i4XMr7txaMv1S0KGRpb2; sessionid=jkj9tj9v8wibnqdx9jxpurugs7cz4vsr",
    "dnt": "1",
    "origin": "https://www.screener.in",
    "pragma": "no-cache",
    "priority": "u=0, i",
    "sec-ch-ua": '"Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"',
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": '"Windows"',
    "sec-fetch-dest": "document",
    "sec-fetch-mode": "navigate",
    "sec-fetch-site": "same-origin",
    "sec-fetch-user": "?1",
    "upgrade-insecure-requests": "1",
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
}

# Define form data
data = {
    "csrfmiddlewaretoken": "WcCFMuVOTyAGs3fvwGEn7UejMS4zblkH7J4X7MPmvYWwAX27NDXK7wzauIE5SAlz",
    "next": "/",
}

# Make the POST request
response = requests.post(url, headers=headers, data=data)

# Check if the request was successful
if response.status_code == 200:
    # Save the response content as an .xlsx file
    with open("ScreenerData.xlsx", "wb") as file:
        file.write(response.content)
    print("File saved as 'ScreenerData.xlsx'.")
else:
    print(f"Failed to download the file. Status code: {response.status_code}")
