Created
November 10, 2023 20:22
-
-
Save FernandoCelmer/d7559a7fba1a180198e22ab569008d07 to your computer and use it in GitHub Desktop.
scrapping.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
pip install selenium | |
pip install webdriver-manager | |
python scrapping.py | |
""" | |
from selenium import webdriver | |
from selenium.webdriver.chrome.service import Service | |
from webdriver_manager.chrome import ChromeDriverManager | |
def chrome_options() -> webdriver.ChromeOptions: | |
chrome_options = webdriver.ChromeOptions() | |
chrome_options.add_argument("--no-sandbox") | |
chrome_options.add_argument("--disable-dev-shm-usage") | |
chrome_options.add_argument("--disable-blink-features=AutomationControlled") | |
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"]) | |
chrome_options.add_experimental_option('useAutomationExtension', False) | |
return chrome_options | |
def chrome_browser(wait: int = 5) -> webdriver.Chrome: | |
driver = webdriver.Chrome( | |
service=Service(ChromeDriverManager().install()), | |
options=chrome_options() | |
) | |
driver.implicitly_wait(wait) | |
return driver | |
def handler() -> dict: | |
driver = chrome_browser() | |
driver.get("http://www.python.org") | |
return { | |
"statusCode": 200, | |
"body": driver.title | |
} | |
print(handler()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment