셀레늄으로 웹 사이트를 긁어 모으기 위해 리눅스 서버에서 헤드리스 모드로 브라우저를 설정하는 python 메소드가 있습니다. 어떤 사용자가 python 스크립트를 실행하든 상관없이 디스플레이는 완벽하게 설정이 잘되지만, sudo
사용자가 스크립트를 실행하지 않으면 설정 라인에 무한정으로 webdriver.Firefox()
이 걸릴 것입니다. 셀레늄 webdriver.Firefox 비 sudo 사용자가 시작되지 않습니다
def browserSetup(self, browser=None):
try:
# now Firefox will run in a virtual display. you will not see the browser.
self.display = Display(visible=0, size=(800, 600))
self.display.start()
if self.verbose:
print "Virtual display started for browser instantiation."
#change user agent
profile = webdriver.FirefoxProfile()
profile.set_preference("general.useragent.override", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/536.30.1 (KHTML, like Gecko) Version/6.0.5 Safari/536.30.1")
profile.set_preference("webdriver.log.file", "webdriver.log")
# Create a new instance of the Firefox driver
browser = webdriver.Firefox(profile)
if self.verbose:
print "Browser window object established @ %s." % browser
return browser
except Exception, e:
raise e
그래서, 내 문제를 반복 : 스크립트가
sudo
로 실행되지 않는 경우
가 다음 스크립트가 webdriver.Firefox
생성 줄에서 무기한 중단됩니다
여기에 전체 방법이다. 왜 이런 일이 일어날까요?
UPDATE : 문제는 여기에이 라인은 다음과 같습니다
browser = webdriver.Firefox() #with or without the profile variable - the results are the same
UPDATE 다시 아래 코멘트에 몇몇 사람들은 내가 수동으로 명령 줄에서 Firefox
를 실행하려고 제안 어떤 문제가 있는지보기. 여기 결과입니다 :
#initialize the virtual display
$ sudo Xvfb :10 -extension RANDR
[dix] Could not init font path element /usr/share/fonts/X11/cyrillic, removing from list!
[dix] Could not init font path element /usr/share/fonts/X11/100dpi/:unscaled, removing from list!
[dix] Could not init font path element /usr/share/fonts/X11/75dpi/:unscaled, removing from list!
[dix] Could not init font path element /usr/share/fonts/X11/Type1, removing from list!
[dix] Could not init font path element /usr/share/fonts/X11/100dpi, removing from list!
[dix] Could not init font path element /usr/share/fonts/X11/75dpi, removing from list!
[dix] Could not init font path element /var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType, removing from list!
#now start firefox in another ssh window (since the Xvfb process is consuming my prompt)
$ export DISPLAY=:10
$ firefox
(firefox:6347): GConf-WARNING **: Client failed to connect to the D-BUS daemon:
//bin/dbus-launch terminated abnormally without any error message
마지막 오류 메시지가 수백 번 표시 ... 난 단지 추측 할 수
파이어 폭스에 대한 사용 권한은 무엇입니까? 방법에 대해'sudo chmod 777 location/to/firefox' 그리고 나서 그것을 시도하십시오. 어둠 속에서 그냥 촬영하기 :'dpkg -L firefox'을 실행하는 – Amey
은'/ usr/lib/firefox'에있는 모든 파이어 폭스 파일을 주로 보여주기 때문에'sudo chmod -R 777/usr/lib/firefox'를 나는 아직도 내 문제가있다.그래서, 그게 내 문제를 해결하지 못했습니다 – sadmicrowave
이것은 일반 사용자로 실행됩니까? 사용자가 작동하지 않는 곳에서 X를 시작할 수있는 권한이 있습니까? – Oz123