Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save evan-kolberg/8df2d50d4c5c753c32b91c1ab8495ceb to your computer and use it in GitHub Desktop.
Save evan-kolberg/8df2d50d4c5c753c32b91c1ab8495ceb to your computer and use it in GitHub Desktop.
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