Sto provando a utilizzare il selenio da Python per scansionare alcune pagine dinamiche con javascript. Tuttavia, non posso chiamare firefox dopo aver seguito le istruzioni del selenio sulla pagina pypi (http://pypi.python.org/pypi/selenium). Ho installato Firefox su AWS ubuntu 12.04. Il messaggio di errore ho ottenuto è:Impossibile chiamare firefox dal selenio in python sul computer AWS
In [1]: from selenium import webdriver
In [2]: br = webdriver.Firefox()
---------------------------------------------------------------------------
WebDriverException Traceback (most recent call last)
/home/ubuntu/<ipython-input-2-d6a5d754ea44> in <module>()
----> 1 br = webdriver.Firefox()
/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.pyc in __init__(self, firefox_profile, firefox_binary, timeout)
49 RemoteWebDriver.__init__(self,
50 command_executor=ExtensionConnection("127.0.0.1", self.profile,
---> 51 self.binary, timeout),
52 desired_capabilities=DesiredCapabilities.FIREFOX)
53
/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.pyc in __init__(self, host, firefox_profile, firefox_binary, timeout)
45 self.profile.add_extension()
46
---> 47 self.binary.launch_browser(self.profile)
48 _URL = "http://%s:%d/hub" % (HOST, PORT)
49 RemoteConnection.__init__(
/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.pyc in launch_browser(self, profile)
42
43 self._start_from_profile_path(self.profile.path)
---> 44 self._wait_until_connectable()
45
46 def kill(self):
/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.pyc in _wait_until_connectable(self)
79 raise WebDriverException("The browser appears to have exited "
80 "before we could connect. The output was: %s" %
---> 81 self._get_firefox_output())
82 if count == 30:
83 self.kill()
WebDriverException: Message: 'The browser appears to have exited before we could connect. The output was: Error: no display specified\n'
ho fatto ricerca sul web e ho trovato che questo problema è accaduto con altre persone (https://groups.google.com/forum/?fromgroups=#!topic/selenium : agli utenti/21sJrOJULZY). Ma non capisco la soluzione, se lo è.
Qualcuno può aiutarmi per favore? Grazie!
'Errore: nessun display specificato' significa che il browser non ha uno schermo per visualizzare la finestra principale su. Dovrai trovare un modo per eseguire Firefox headless: http://stackoverflow.com/questions/10060417/python-firefox-headless. Questa risposta in particolare sembra utile: http://stackoverflow.com/a/6300672/464744 – Blender
@Blender Grazie mille. Il secondo link ha risolto il mio problema. A volte non riesco a trovare la soluzione da google se non ho la parola chiave giusta nella mia mente. – David
@Blender: come hai ottenuto un'ancora nel tuo URL per una risposta in una pagina?Non vedo link come questo nelle pagine. –