To accomplish this task, you'll need to create a Python script that performs an HTTP GET request using the requests library, parses the response content to locate a specific JavaScript snippet, extracts a link, and prints it. Below is an example script to achieve this:
First, ensure you have the required requests library. You can install it via pip if you haven't yet:
pip install requests
Now, here is a Python script that does what you described:
import requests
import re
# Define the URL and headers
url = "https://trigonevo.fun/whitelist/?HWID=83123123123123"
headers = {
"pragma": "no-cache",
"cache-control": "no-cache",
"sec-ch-ua": '"Brave";v="129", "Not=A?Brand";v="8", "Chromium";v="129"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"Windows"',
"upgrade-insecure-requests": "1",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36",
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8",
"sec-gpc": "1",
"accept-language": "en-US,en;q=0.8",
"sec-fetch-site": "none",
"sec-fetch-mode": "navigate",
"sec-fetch-user": "?1",
"sec-fetch-dest": "document",
"accept-encoding": "gzip, deflate, br, zstd",
"cookie": "trigonevo_session=70lvnnr5mi015j2t6eiikbem4g",
"priority": "u=0, i"
}
# Initiate a session
session = requests.Session()
# Send GET request
response = session.get(url, headers=headers)
# Ensure successful request
if response.status_code == 200:
# Regular expression to find the JavaScript snippet
onclick_pattern = re.compile(r"window\.location\.href=\'(https://link-to\.net/.*?)\'")
# Search through the content
match = onclick_pattern.search(response.text)
if match:
# Extract the link
link_to_net_url = match.group(1)
print("Extracted link:", link_to_net_url)
else:
print("No matching onclick pattern found.")
else:
print(f"Failed to retrieve content: Status code {response.status_code}")
Explanation:
- requests.Session(): Creates a session object to manage and persist settings like cookies across requests.
- GET request: Uses the session object to send a GET request to the specified URL with the custom headers.
- Regex Search: Utilizes a regular expression to search for the specific
window.location.href JavaScript snippet within the response text. The regex pattern is carefully crafted to match the required format.
- Extract and Print: If it finds a match, it extracts the link and prints it. Otherwise, it prints a message indicating no matching pattern was found.
This script assumes the HTTP response is properly formatted and contains the expected JavaScript snippet. You may need to refine the regex pattern based on any variations in the HTML structure. Additionally, error handling and checking the exact path of the desired element are crucial for robust script performance.