How to get source code with headers request from protected dynamic javascript

47 Views Asked by At

I want to obtain the source code from a dynamic JavaScript website, it is necessary to send the request with headers.

I attempted to do this using Selenium, but I am unsure how to include the headers in the request.

I try to use headers=headers, but it marks it as an unexpected argument.

from selenium import webdriver


def download_page(url):
    # Enviar los headers necesarios para que la página se cargue correctamente
    headers = {
        "User-Agent": "example",
        "token": "example"
    }

    driver = webdriver.Chrome()

    driver.get(url, headers=headers)

    driver.implicitly_wait(10)

    source = driver.page_source

    driver.close()

    return source


if __name__ == "__main__":
    url = "https://example.com/"

    source = download_page(url)

    print(source)
0

There are 0 best solutions below