Last active
March 14, 2025 18:48
-
-
Save Nikolaj-K/7caa6ec184a07af1f8fe74f7860591c5 to your computer and use it in GitHub Desktop.
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 | |
from selenium import webdriver | |
from webdriver_manager.chrome import ChromeDriverManager | |
from selenium.webdriver.chrome.service import Service | |
import time | |
class Config: | |
URL = "https://testnet.somnia.network/memecoins" | |
TMP_FILE_PATH = "/path/to/write/somnia_memecoin_page_tmp.html" | |
def fetch_and_save_to_file(url, file_path): | |
options = webdriver.ChromeOptions() | |
options.add_argument("--headless") | |
options.add_argument("--no-sandbox") | |
options.add_argument("--disable-dev-shm-usage") | |
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options) | |
driver.get(url) | |
time.sleep(10) | |
try: | |
page_source = driver.page_source | |
with open(file_path, "w", encoding="utf-8") as file: | |
file.write(page_source) | |
#print(f"Page content has been successfully saved to {file_path}") | |
except Exception as e: | |
print("Error fetching page content:", e) | |
finally: | |
driver.quit() | |
def parse_prices_from_file(file_path): | |
with open(file_path, "r", encoding="utf-8") as file: | |
page_content = file.read() | |
price_pattern = r">\$([\d]*\.[\d]+)[ <]" | |
prices = re.findall(price_pattern, page_content) | |
return [float(price) for price in prices] | |
if __name__ == "__main__": | |
fetch_and_save_to_file(Config.URL, Config.TMP_FILE_PATH) | |
prices = parse_prices_from_file(Config.TMP_FILE_PATH) | |
print(f"Prices:\nSomini=${prices[0]}\nSomsom=${prices[1]}\n Somi=${prices[2]}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment