-
Notifications
You must be signed in to change notification settings - Fork 16
/
selenium-web.py
31 lines (28 loc) · 1021 Bytes
/
selenium-web.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import time
from selenium import webdriver
import os
from selenium.webdriver.common.keys import Keys
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 800))
display.start()
chrome_options = webdriver.ChromeOptions()
# below trick saved my life
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
#chrome_options.add_argument('--no-sandbox')
#chrome_options.add_argument("headless")
# set the folder where you want to save your file
prefs = {'download.default_directory' : os.getcwd()}
chrome_options.add_experimental_option('prefs', prefs)
# Optional argument, if not specified will search path.
driver = webdriver.Chrome('/usr/local/bin/chromedriver',chrome_options=chrome_options,service_args=['--verbose', '--log-path=/tmp/chromedriver.log'])
chrome_options=chrome_options
# Scraping steps
driver.get("http://54.201.142.247/")
time.sleep(3)
print(driver.title)
time.sleep(3)
print(' [*] Finished!')
print(driver.current_url)
driver.close()
driver.quit()