(Oct-15-2018, 11:09 PM)Truman Wrote: I guess that this #--| Setup part can be used in other scripts too. Will save it.Yes can use it for all when work parse or automation ,just comment out
--headless
then it work without.Example search and show images of cars.
from selenium import webdriver from selenium.webdriver.firefox.options import Options from selenium.webdriver.common.keys import Keys import time #--| Setup options = Options() #options.add_argument("--headless") caps = webdriver.DesiredCapabilities().FIREFOX caps["marionette"] = True browser = webdriver.Firefox(firefox_options=options, capabilities=caps, executable_path=r"geckodriver.exe") #--| Parse or automation browser.get('https://duckduckgo.com') input_field = browser.find_elements_by_css_selector('#search_form_input_homepage') input_field[0].send_keys('car' + Keys.RETURN) time.sleep(3) images_link = browser.find_elements_by_link_text('Images') images_link[0].click() time.sleep(5) browser.quit()
Quote:if I want to listen to music for some time? Would try it myself but first have to figure out how to stop music.No
time.sleep()
is not for that,you have to push start and stop button on web-site that has music.Also you find button eg bye CSS selector,then call
click()
on eg stop button.