init
This commit is contained in:
61
download_data.py
Normal file
61
download_data.py
Normal file
@@ -0,0 +1,61 @@
|
||||
import requests
|
||||
import re
|
||||
import json
|
||||
import ast
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
def extract_data_from_page(url):
|
||||
response = requests.get(url)
|
||||
response.raise_for_status()
|
||||
with open("response.html", "w", encoding="utf-8") as f:
|
||||
f.write(response.text)
|
||||
soup = BeautifulSoup(response.text, 'html.parser')
|
||||
script_tags = soup.find_all('script')
|
||||
|
||||
for script in script_tags:
|
||||
if script.string:
|
||||
lines = script.string.split('\n')
|
||||
for line in lines:
|
||||
if re.match(r'^\s*data\s*=', line):
|
||||
match = re.search(r'data\s*=\s*(.+)', line)
|
||||
if match:
|
||||
data_str = match.group(1).rstrip(';').strip()
|
||||
try:
|
||||
data = ast.literal_eval(data_str)
|
||||
return data
|
||||
except (ValueError, SyntaxError):
|
||||
continue
|
||||
raise ValueError("Data object not found in script tags")
|
||||
|
||||
if __name__ == "__main__":
|
||||
url = "https://ely.gg"
|
||||
data = extract_data_from_page(url)
|
||||
new_data = {}
|
||||
|
||||
replacement_map = {
|
||||
'greater chain codex': 'Greater Chain ability codex',
|
||||
'Fractured Armadyl Symbol (Kerapac)': 'Fractured Armadyl Symbol',
|
||||
'Fractured Stabilization Gem (Kerapac)': 'Fractured Stabilisation Gem',
|
||||
'Loved Up Walk Override': 'Loved Up Walk Override Token',
|
||||
'Mizyuyari': 'Mizuyari',
|
||||
'O lantern title scroll': "'o'-lantern' title scroll",
|
||||
'OG Gem Cape Token': 'Gem cape token',
|
||||
'Robin': 'Robin (item)',
|
||||
'Red Santa Hat': 'Santa Hat',
|
||||
"One of the many title scroll": "'O ne of the many' title scroll",
|
||||
"Party Title Scroll": "'Party' title scroll",
|
||||
}
|
||||
|
||||
for item in data:
|
||||
if 'inverted' in item['value'].lower():
|
||||
item['value'] = item['value'].replace('(120)', 'token')
|
||||
|
||||
for original_key, replacement_value in replacement_map.items():
|
||||
if item['value'].lower() == original_key.lower():
|
||||
item['value'] = replacement_value
|
||||
break
|
||||
|
||||
new_data[item['value'].strip()] = item['id']
|
||||
|
||||
with open('chrome-extension/new_data.json', 'w') as f:
|
||||
json.dump(new_data, f, indent=4)
|
||||
Reference in New Issue
Block a user