from selenium import webdriver import selenium.webdriver.chrome.service as service # This template uses ChromeDriverService, allowing you to start/stop ChromeDriver servers yourself with .quit() # This template saves significant amount of time for large test suites where a ChromeDriver instance is created per test service = service.Service('C:/Users/joshua/Downloads/chromedriver_win32/chromedriver_72.exe') service.start() capabilities = {'chrome.binary': 'C:/Users/joshua/Downloads/chromedriver_win32'} driver = webdriver.Remote(service.service_url, capabilities) # Open to a specific url driver.get('http://inventwithpython.com'); # Any additional commands here # Close remote-in browser time.sleep(5) # So that you can see the process take place driver.quit() # I don't think this is necessary, but running scratch files without this command showed that there was a separate # background process (4mb/process) for each time chromedriver.exe was called in service.start() However, driver.quit() # already quits the remote in service. Not sure what exactly caused it though. # Just to be safe... service.stop()
#browser = webdriver.Chrome() #browser.delete_all_cookies() globaltop = 'alexaglobaltop.txt' ustop = 'alexaustop.txt' globaltop = codecs.open(globaltop, encoding = 'utf-8', mode = 'w') ustop = codecs.open(ustop, encoding = 'utf-8', mode = 'w') urlp1 = "http://www.alexa.com/" urlp2 = "topsites/global;" pages = [] #browser.get('http://www.alexa.com/topsites/global;0') browser.get('http://www.baidu.com') service.stop() service.start() for i in range(0, 4): pages.append(str(i)) for urlp3 in pages: url = urlp1 + urlp2 + urlp3 browser.get(url) """ site_listing = browser.find_elements_by_class_name("site-listing") for website in site_listing: name = website.find_element_by_tag_name("h2").find_element_by_tag_name("a").text link = website.find_element_by_class_name("topsites-label").text globaltop.write(name + '\n' + link + '\n\n') """ """ urlp2 = "topsites/countries;"
def closeDriver(service, driver): driver.quit() service.stop()
from typing import TextIO from selenium import webdriver from datetime import datetime import selenium.webdriver.chrome.service as service service = service.Service('C:/chromedriver.exe') service.start() driver = webdriver.Remote(service.service_url) driver.get('https://yandex.ru/time/') # открываем страницу f: TextIO = open("log.txt", "w", encoding='utf-8') # открываем файл для записи if datetime.strftime( datetime.now(), "%H:%M") in driver.title: # проверяем есть ли системное время в title f.write( datetime.strftime(datetime.now(), "%H:%M:%S") + " — УСПЕХ: " + datetime.strftime(datetime.now(), "%H:%M") + "=" + driver.title[0:5]) else: # записываем результат проверки f.write( datetime.strftime(datetime.now(), "%H:%M:%S") + " — ОШИБКА: " + datetime.strftime(datetime.now(), "%H:%M") + "≠" + driver.title[0:5]) f.close() # закрываем файл service.stop() # останавливаем Chromedriver