I would like to scrape a website for its "raw" JavaScript code. For example, if I were to scrape this website. I would get a string containing:
This is just a small portion of the existing JS in the given link, but I would like to obtain the entire JS in a string or array of strings.
I have tried different approaches to obtain this data: using requests and selenium.
Simply loading the HTML of the website doesn't seem to work, as the script tags don't seem to load.
Using selenium, I hoped this would work:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
url = "https://www.udemy.com"
driver = webdriver.Chrome()
driver.get(url)
wait = ui.WebDriverWait(driver, 10)
results = wait.until(EC.visibility_of_all_elements_located((By.TAG_NAME, "script")))
print(results)
Then using results I could get a string, but it doesn't work.
Another example for the JS Scripts chunks I'd like to get:
The red rectangle indicates JS Scripts, as you can see there is a lot of it and I would like to get it in its "raw" form (not execute it).
My question is: How would I get the "raw" JS script in a string format? and what is the most efficient way (time-wise) to perform this?

