<?xml version="1.0" encoding="utf-8" ?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:tt="http://teletype.in/" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/"><title>Mr. Mody</title><author><name>Mr. Mody</name></author><id>https://teletype.in/atom/modykun380</id><link rel="self" type="application/atom+xml" href="https://teletype.in/atom/modykun380?offset=0"></link><link rel="alternate" type="text/html" href="https://teletype.in/@modykun380?utm_source=teletype&amp;utm_medium=feed_atom&amp;utm_campaign=modykun380"></link><link rel="next" type="application/rss+xml" href="https://teletype.in/atom/modykun380?offset=10"></link><link rel="search" type="application/opensearchdescription+xml" title="Teletype" href="https://teletype.in/opensearch.xml"></link><updated>2026-05-26T04:09:37.745Z</updated><entry><id>modykun380:ArI1Ff3y99</id><link rel="alternate" type="text/html" href="https://teletype.in/@modykun380/ArI1Ff3y99?utm_source=teletype&amp;utm_medium=feed_atom&amp;utm_campaign=modykun380"></link><title>python code to get the source code for a spasific site in folder ☕</title><published>2025-02-07T17:56:56.629Z</published><updated>2025-02-07T17:56:56.629Z</updated><summary type="html">import requests
from bs4 import BeautifulSoup
import os</summary><content type="html">
  &lt;p id=&quot;fzIo&quot;&gt;import requests&lt;br /&gt;from bs4 import BeautifulSoup&lt;br /&gt;import os&lt;/p&gt;
  &lt;p id=&quot;Qicr&quot;&gt;def get_source_code(url):&lt;br /&gt; try:&lt;br /&gt; response = requests.get(url)&lt;br /&gt; response.raise_for_status() # Raise an exception for HTTP errors&lt;br /&gt; return response.text&lt;br /&gt; except requests.exceptions.RequestException as e:&lt;br /&gt; print(f&amp;quot;An error occurred: {e}&amp;quot;)&lt;br /&gt; return None&lt;/p&gt;
  &lt;p id=&quot;HrkU&quot;&gt;def save_file(content, file_path):&lt;br /&gt; with open(file_path, &amp;#x27;w&amp;#x27;, encoding=&amp;#x27;utf-8&amp;#x27;) as file:&lt;br /&gt; file.write(content)&lt;/p&gt;
  &lt;p id=&quot;clBo&quot;&gt;def extract_and_save_resources(url):&lt;br /&gt; # Fetch the HTML content&lt;br /&gt; html_content = get_source_code(url)&lt;br /&gt; if not html_content:&lt;br /&gt; return&lt;/p&gt;
  &lt;p id=&quot;apzK&quot;&gt;# Save the HTML content&lt;br /&gt; html_file_path = &amp;#x27;index.html&amp;#x27;&lt;br /&gt; save_file(html_content, html_file_path)&lt;br /&gt; print(f&amp;quot;HTML content saved to {html_file_path}&amp;quot;)&lt;/p&gt;
  &lt;p id=&quot;CjFb&quot;&gt;# Parse the HTML content&lt;br /&gt; soup = BeautifulSoup(html_content, &amp;#x27;html.parser&amp;#x27;)&lt;/p&gt;
  &lt;p id=&quot;hZxt&quot;&gt;# Extract and save CSS files&lt;br /&gt; for link in soup.find_all(&amp;#x27;link&amp;#x27;, rel=&amp;#x27;stylesheet&amp;#x27;):&lt;br /&gt; css_url = link.get(&amp;#x27;href&amp;#x27;)&lt;br /&gt; if css_url:&lt;br /&gt; css_content = get_source_code(css_url)&lt;br /&gt; if css_content:&lt;br /&gt; css_file_path = os.path.join(&amp;#x27;css&amp;#x27;, os.path.basename(css_url))&lt;br /&gt; os.makedirs(os.path.dirname(css_file_path), exist_ok=True)&lt;br /&gt; save_file(css_content, css_file_path)&lt;br /&gt; print(f&amp;quot;CSS content saved to {css_file_path}&amp;quot;)&lt;/p&gt;
  &lt;p id=&quot;I11i&quot;&gt;# Extract and save JavaScript files&lt;br /&gt; for script in soup.find_all(&amp;#x27;script&amp;#x27;, src=True):&lt;br /&gt; js_url = script.get(&amp;#x27;src&amp;#x27;)&lt;br /&gt; if js_url:&lt;br /&gt; js_content = get_source_code(js_url)&lt;br /&gt; if js_content:&lt;br /&gt; js_file_path = os.path.join(&amp;#x27;js&amp;#x27;, os.path.basename(js_url))&lt;br /&gt; os.makedirs(os.path.dirname(js_file_path), exist_ok=True)&lt;br /&gt; save_file(js_content, js_file_path)&lt;br /&gt; print(f&amp;quot;JS content saved to {js_file_path}&amp;quot;)&lt;/p&gt;
  &lt;p id=&quot;tVe3&quot;&gt;# Example usage&lt;br /&gt;url = &amp;#x27;&lt;a href=&quot;https://example.com&quot; target=&quot;_blank&quot;&gt;https://example.com&lt;/a&gt;&amp;#x27;&lt;br /&gt;extract_and_save_resources(url)&lt;/p&gt;

</content></entry></feed>