<filename>Day 4/webfiles_extractor/extractor.py<gh_stars>1-10
#webfiles_extractor.py
import requests
from bs4 import BeautifulSoup as bs
from urllib.parse import urljoin

# pip install bs4
""" This is a python script that extract all the Javascript and CSS links/files of a website""" 

print("Make sure to enter the website url in - \n  http or https i.e https://websitename.com \n    or http://webname.com")
# URL of the web page you want to extract

url = input("Url of webpage to extract in http[s]: ")
#url = "http://moralistdev.000webhostapp.com"

# initialize a session
session = requests.Session()
# set the User-agent as a regular browser
session.headers["User-Agent"] = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36"

# get the HTML content
html = session.get(url).content

# parse HTML using beautiful soup
soup = bs(html, "html.parser")

# get the JavaScript files
script_files = []

for script in soup.find_all("script"):
    if script.attrs.get("src"):
        # if the tag has the attribute 'src'
        script_url = urljoin(url, script.attrs.get("src"))
        script_files.append(script_url)

# get the CSS files
css_files = []

for css in soup.find_all("link"):
    if css.attrs.get("href"):
        # if the link tag has the 'href' attribute
        css_url = urljoin(url, css.attrs.get("href"))
        css_files.append(css_url)


print("Total script files in the page:", len(script_files))
print("Total CSS files in the page:", len(css_files))

# write file links into files
with open("javascript_files.txt", "w") as f:
    for js_file in script_files:
        print(js_file, file=f)

with open("css_files.txt", "w") as f:
    for css_file in css_files:
        print(css_file, file=f)
<filename>Day 4/webfiles_extractor/extractor.py<gh_stars>1-10
#webfiles_extractor.py
import requests
from bs4 import BeautifulSoup as bs
from urllib.parse import urljoin

# pip install bs4
""" This is a python script that extract all the Javascript and CSS links/files of a website""" 

print("Make sure to enter the website url in - \n  http or https i.e https://websitename.com \n    or http://webname.com")
# URL of the web page you want to extract

url = input("Url of webpage to extract in http[s]: ")
#url = "http://moralistdev.000webhostapp.com"

# initialize a session
session = requests.Session()
# set the User-agent as a regular browser
session.headers["User-Agent"] = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36"

# get the HTML content
html = session.get(url).content

# parse HTML using beautiful soup
soup = bs(html, "html.parser")

# get the JavaScript files
script_files = []

for script in soup.find_all("script"):
    if script.attrs.get("src"):
        # if the tag has the attribute 'src'
        script_url = urljoin(url, script.attrs.get("src"))
        script_files.append(script_url)

# get the CSS files
css_files = []

for css in soup.find_all("link"):
    if css.attrs.get("href"):
        # if the link tag has the 'href' attribute
        css_url = urljoin(url, css.attrs.get("href"))
        css_files.append(css_url)


print("Total script files in the page:", len(script_files))
print("Total CSS files in the page:", len(css_files))

# write file links into files
with open("javascript_files.txt", "w") as f:
    for js_file in script_files:
        print(js_file, file=f)

with open("css_files.txt", "w") as f:
    for css_file in css_files:
        print(css_file, file=f)
#webfiles_extractor.py # pip install bs4 This is a python script that extract all the Javascript and CSS links/files of a website # URL of the web page you want to extract #url = "http://moralistdev.000webhostapp.com" # initialize a session # set the User-agent as a regular browser # get the HTML content # parse HTML using beautiful soup # get the JavaScript files # if the tag has the attribute 'src' # get the CSS files # if the link tag has the 'href' attribute # write file links into files