任何方式运行带有GreaseMonkey脚本的Firefox没有GUI / X会话 [英] Any way to run Firefox with GreaseMonkey scripts without a GUI/X session
问题描述
我需要为第三方网站(这是一个具有我们访问者统计数据的外部网站)构建一个小的监控刮刀。
I need to build a small "monitoring" scraper for a 3rd party website (it's an external website that has stats about our visitors).
不幸的是,是很难通过正常的wget机制,因为它使用了一吨复杂的JS,它的一部分是由GWT生成的。所以我的解决方法是创建一个GreaseMonkey脚本,然后让这个脚本调用一个PHP页面,将记录抓取的数据。
Unfortunately, this website is very hard to scrape through the normal "wget" mechanism, because it uses a ton of sophisticated JS, part of it generated by GWT. So my workaround was to create a GreaseMonkey script and then have this script call a PHP page that would log the scraped data. Then as soon as Firefox starts with this webpage-to-scrape, the script goes to work.
这个工作很好,但现在我想让它更健壮,因为就像监控工具一样。我希望它在服务器上使用cron作业运行。据我理解这样的事情,这需要一个DISPLAY变量设置和X会话存在(Firefox拒绝为我运行)。有没有什么好的方法允许它作为cron作业从batchuser帐户运行?
This works well, but now I am trying to make it more robust as far as monitoring tools go. I want it to run on the server using a cron job. As far as I understand such things, this requires a DISPLAY variable to be set and for an X session to exist (Firefox is refusing to run for me). Is there any nice way to allow it to run from the batchuser account as a cron job?
推荐答案
得到Selenium在服务器上运行无头。我使用Xvfb。
I've done something similar to get Selenium running headless on a server. I used Xvfb.
http:// en .wikipedia.org / wiki / Xvfb
本文提供了在Firefox中使用Xvfb的一些提示:
This article has some tips for using Xvfb with Firefox:
http://semicomplete.com/blog/geekery/xvfb-firefox.html
这篇关于任何方式运行带有GreaseMonkey脚本的Firefox没有GUI / X会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!