Created
April 9, 2022 18:31
-
-
Save evan-kolberg/8df2d50d4c5c753c32b91c1ab8495ceb to your computer and use it in GitHub Desktop.
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
from selenium.webdriver import Firefox | |
from selenium.webdriver.firefox.options import Options as FirefoxOptions | |
from selenium.webdriver.firefox.service import Service | |
from webdriver_manager.firefox import GeckoDriverManager | |
from bs4 import BeautifulSoup | |
user_agent = '''Mozilla/5.0 (Linux; Android 8.0.0; Pixel 2 XL Build/OPD1.170816.004) | |
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Mobile Safari/537.36''' | |
options = FirefoxOptions() | |
options.set_preference('--general.useragent.override', user_agent) | |
options.add_argument('--width=960') | |
options.add_argument('--height=540') | |
driver = Firefox(service=Service(GeckoDriverManager().install()), options=options) | |
driver.get('https://google.com') | |
soup = BeautifulSoup(driver.page_source, 'html.parser') | |
print('\n' + soup.find('img')['alt'], 'is working!') | |
driver.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment