-1

I'm trying to scrape a website to get the pictures and all I'm interested in is their links. Which I have to wait till the website javascript loads. I'm able to get the information I need, but I don't need firefox to open every time I run my code. Is there a way to just load my html code without the browser opening everytime?

import selenium
from selenium import webdriver

driver = selenium.webdriver.Firefox()
driver.get("https://www.nasa.gov/multimedia/imagegallery/iotd.html")

print(driver.page_source)

2 Answers2

1

The answer by @s.bridges will work, but set_headless() has been deprecated. So you should use the headless property instead. Like this:

from selenium import webdriver
from selenium.webdriver.firefox.options import Options

options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)
driver.get("https://www.nasa.gov/multimedia/imagegallery/iotd.html")
Corey Goldberg
  • 59,062
  • 28
  • 129
  • 143
0

Do you mean run it headless? This will allow Firefox to be used but not visibly.

I went to pull up the docs and saw this was a pretty solid post on setting up headless Firefox.

from selenium import webdriver
from selenium.webdriver.firefox.options import Options

options = Options()
options.set_headless(headless=True)
driver = webdriver.Firefox(firefox_options=options, executable_path=r'C:\Utility\BrowserDrivers\geckodriver.exe')
driver.get("https://www.nasa.gov/multimedia/imagegallery/iotd.html")
print(driver.page_source)
driver.quit()

Hope this answers your question!

Reference

s.bridges
  • 106
  • 2
  • 7
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/20799728) – Sal-laS Sep 07 '18 at 13:40
  • @Salman Thank you. I didn't give it much thought to that. Will do from now on! – s.bridges Sep 07 '18 at 14:42