duanjiao8007 2013-08-17 02:11 采纳率: 100%
浏览 183
已采纳

Python:无法通过脚本启动Selenium Webdriver(Firefox),但它可以通过命令行工作

Title says it all. I'm using webdriver on a remote webserver without a GUI. From the command line, I can do this and everything works fine:

from selenium import webdriver
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800,600))
display.start()
browser = webdriver.Firefox()

I.e., I can navigate the web, get urls, get source code, and everything else with the browser instance. But trying to execute a script on the server containing the same lines doesn't work. It might be relevant that the script is executed via PHP. Everything in the script works up until browser = webdriver.Firefox() - that is, the imports and display stuff all work fine. It's just that last line; for some reason, the browser doesn't want to open when a script tries to do it. This makes no sense and I'm really stumped. Possible reasons/fixes? Maybe something to do with permissions?

EDIT

Just to clarify, I'm doing this all on the remote server. By command line I'm using SSH with PUTTY, and when I try testing the script, I simply do it on the website.

  • 写回答

1条回答 默认 最新

  • douyun8885 2013-08-21 06:10
    关注

    Solved it by changing the permissions of the folder containing the Python script that called the webdriver from 755 to 757 (i.e., I gave write permissions to all users). I'm not sure whether this was a quirk of my situation because of something else I overlooked or whether there's actual insight to be gained here, but I'd say the take home lesson is if weird stuff is happening when working on an unfamiliar server, check the permissions.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题