Skip to content

Instantly share code, notes, and snippets.

@DastanIqbal
Created April 12, 2024 20:50
Show Gist options
  • Save DastanIqbal/1bd7ad0869a9d8a9adb2f3ecf04985b1 to your computer and use it in GitHub Desktop.
Save DastanIqbal/1bd7ad0869a9d8a9adb2f3ecf04985b1 to your computer and use it in GitHub Desktop.
Extract Deals from the website
import re
import requests
def extract_second_parameter_from_js(url):
# Load JavaScript file from the URL
response = requests.get(url)
# Check if the request was successful
if response.status_code == 200:
pattern = r'collection\(deal/v1\)/v1'
# Replacement string
replacement = 'collection/deal/v1/v1'
# Perform the replacement
js_code = re.sub(pattern, replacement, response.text)
# Use regular expression to find the second parameter of assets.mountWidget() method
match = re.search(r'assets\.mountWidget\(\s*([^,]+),\s*([^)]+)\)', js_code)
if match:
second_parameter = match.group(2)
return second_parameter.strip("'\"") # Remove surrounding quotes if any
else:
return None # If assets.mountWidget() method or second parameter is not found
else:
print("Failed to load JavaScript file from the URL")
return None
# Example usage:
url = "https://www.<website>.ae/deals"
second_param = extract_second_parameter_from_js(url)
print(second_param)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment