-
Notifications
You must be signed in to change notification settings - Fork 0
/
1_scrape_to_html.py
40 lines (30 loc) · 1.2 KB
/
1_scrape_to_html.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os
import requests
import logging
logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")
# Configuration
SCRAPE_URL = "https://docs.scroll.io/en/developers/scroll-contracts/" # Replace with the actual URL to scrape
OUTPUT_DIR = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "scRape"))
OUTPUT_HTML_FILE = os.path.join(OUTPUT_DIR, "scroll-contract-addresses.html")
def fetch_html(url):
try:
response = requests.get(url)
response.raise_for_status()
logging.info(f"Successfully fetched HTML from '{url}'.")
return response.text
except requests.RequestException as e:
print(f"Error fetching the URL '{url}': {e}")
return None
def save_html(html_content, output_file):
os.makedirs(os.path.dirname(output_file), exist_ok=True)
with open(output_file, "w", encoding="utf-8") as f:
f.write(html_content)
logging.info(f"Saved HTML content to '{output_file}'.")
def main():
html_content = fetch_html(SCRAPE_URL)
if html_content:
save_html(html_content, OUTPUT_HTML_FILE)
else:
logging.error("Failed to fetch HTML content. Exiting.")
if __name__ == "__main__":
main()