Created
April 12, 2024 20:50
-
-
Save DastanIqbal/1bd7ad0869a9d8a9adb2f3ecf04985b1 to your computer and use it in GitHub Desktop.
Extract Deals from the website
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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