Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Headless browser
#9
(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.
Reply


Messages In This Thread
Headless browser - by Truman - Oct-13-2018, 10:36 PM
RE: Headless browser - by metulburr - Oct-14-2018, 12:04 AM
RE: Headless browser - by Truman - Oct-14-2018, 11:29 PM
RE: Headless browser - by Larz60+ - Oct-14-2018, 12:15 AM
RE: Headless browser - by metulburr - Oct-14-2018, 11:52 PM
RE: Headless browser - by Truman - Oct-15-2018, 12:14 AM
RE: Headless browser - by snippsat - Oct-15-2018, 01:00 AM
RE: Headless browser - by Truman - Oct-15-2018, 11:09 PM
RE: Headless browser - by snippsat - Oct-16-2018, 01:06 PM
RE: Headless browser - by Truman - Oct-16-2018, 10:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Headless Chrome: How to login into a webpage? amandacstr 1 4,356 Feb-06-2020, 02:19 AM
Last Post: metulburr
  error when running headless selenium julio2000 2 4,645 Feb-01-2020, 12:41 PM
Last Post: julio2000
  Unable to access javaScript generated data with selenium and headless FireFox. pjn4 0 2,592 Aug-04-2019, 11:10 AM
Last Post: pjn4
  webdriver.remote to connect back existing browser without open new browser? gahhon 6 6,873 Feb-26-2019, 03:53 PM
Last Post: gahhon
  Selenium with headless firefox is slow mgtheboss 4 15,090 Jan-13-2018, 09:03 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020