capture web page using cutycapt or PhantomJs? - screenshot

I want to take screenshot from my web automatically using crontab. I have installed cutycapt on my server. But I get this error when running it :
My question is :
What's wrong with that error ?
What is the best way to capture screenshot of my web page, cutycapt
or phantomjs ?
What is needed to use cutycapt or phantomjs ? I don't understand how
cutycapt or phantomjs works.
I'll be grateful if there is any one who can explain this to me. Thanks.

To get it to work in a "headless" environment I used xvfb, I'd already installed xserver, but I do not believe it is required. I did not intentionally install phantomjs, but it may be a dependancy.
sudo apt-get install xvfb cutycapt
And I then launched cutycapt in an xvfb framebuffer and sent some arguments. This is taken from the cutycapt source forge usage page.
xvfb-run --server-args="-screen 0, 1024x768x24" cutycapt --url=website.com --out=image.png
I also wrote a little script to make it even easier. It asks you which page to download. saves it as as the the url.png
#!/bin/bash
echo what is the website you would like to grab?
read url
echo grabbing $url please wait...
xvfb-run --server-args="-screen 0, 1024x768x24" cutycapt --url=$url --out=$url.png
echo done, image is $url.png

The error message means CutyCapt needs a X server running. PhantomJS 2.x is headless, it does not need a X server running.

Related

problems with ubiquity/success_command Ubuntu 14.04

I want to automate the Ubuntu installation (a fully unattended installation without questions). I also want to run a script right after the installation is finished.
What I did is that I managed to have a fully unattended Ubuntu installation. I am doing this by providing a pre-seed file and using boot parameters to preseed the questions that are asked before the preseed file is loaded. The installation went okay but the problem lies with running the script right after the installation completion. I am using Ubuntu 14.04 LTS desktop version thus I am not using the late command as I have read that it won't be noticed by the installer. Instead, I am using the Ubiquity/success_command. I have the following code at the end of my pre-seed file.
ubiquity ubiquity/success_command string \
mkdir /target/dev-master/; \
cp -r /cdrom/dev-master/* /target/dev-master/; \
chroot /target bash /dev-master/SCRIPT;
The problem is nothing happens. I think the command went unnoticed as well.
I am not sure if I am approaching the problem correctly.
What am I doing wrong ?
Is there any other alternatives that might provide the desired result ? Any help would be appreciated and thanks.

How do I enable WebGL in headless chrome in Ubuntu?

How do I enable webgl or install webgl in headless chrome in Ubuntu 14? I tried installing libosmesa6, but that did not help.
Can someone please point me in the right direction?
I want to use webgl to work with headless chrome and selenium tests? I am using nightwatch to run the tests.
This worked for me to get chrome to use osmesa
sudo apt-get install libosmesa
sudo ln -s /usr/lib/x86_64-linux-gnu/libOSMesa.so.6 /opt/google/chrome/libosmesa.so
google-chrome --no-first-run --user-data-dir=~/chrome-stuff --use-gl=osmesa
Warning: When running with osmesa the entire page is rendered with osmesa making it pretty slow. So, if there are tests you have that can run without WebGL you probably want to run them without osmesa.
Also note that chrome itself uses osmesa to headless test but it uses a specific version. At the time of this answer it was version 9.0.3. It also makes a few changes listed here
Otherwise to run headless in general I found this
https://gist.github.com/addyosmani/5336747

Installing Codeception without local web application

Can I install and use Codeception without a web application stored locally? I tried downloading codecept.phar to its own directory, but when I run "php codecept.phar bootstrap" I get "c??????" in front of my console prompt. Please advise, thanks.
Short answer: yes. Longer answer: I needed to upgrade my version of PHP.

A GUI to debug phantomjs script

I am using phantomjs to build a web crawler. My current crawler is a Python script using selenium, which requires a running Firefox browser. While Selenium is good for debugging scripts (as I can use firebug to inspect the webpage), it cannot be deployed on linux servers without GUI. So I am trying to translate my Python script to phantomjs.
To debug phantomjs scripts, I save the page source html and render a png screenshot to disk, and open it in Firefox to inspect the source page. I am wondering if there is a better way to do this, e.g. a plugin for phantomjs, etc.
This little hack is using a simple technique: It grabs the screen as PhantomJS or CasperJS sees it with captureBase64('png') and then it is POSTing the image into the receiving server which then sends it via socket.io to the browser which displays it is as inline image.
The source code is available on github:
https://github.com/maciejjankowski/flaming-octo-puss
I'm not sure if PhantomJS has it, but CasperJS does (and the latter adds some extra functions to PhantomJS)
and use remote debugging as others suggest
As for most of the JS scripts, it's not so trivial to debug phantomjs script, because there is no IDE/compiler behind this.
First, I higly suggest you to read the Troubleshooting section.
As said by torazaburo, your best option is to use Remote Debugging : scripts can be run in a Web Inspector interface-like console : step-in, step-out, break points, local variables... many classic debugger features are available. If you're familliar with Chrome developpers tools, it's pretty the same.
Though not a solution to your Phantomjs troubles,I think Selenium with Python bindings can be used very efficiently as a headless scraper in a Linux environment.
You can use PyVirtualDisplay, a Python wrapper for Xvfb and Xephyr to fake a display.PyVirtualDisplay needs Xvfb as a dependency. On Ubuntu, first install Xvfb:
sudo apt-get install xvfb
then install PyVirtualDisplay from Pypi:
pip install pyvirtualdisplay
Sample Selenium script in Python in a headless mode with PyVirtualDisplay:
#!/usr/bin/env python
from pyvirtualdisplay import Display
from selenium import webdriver
display = Display(visible=0, size=(800, 600))
display.start()
# now Firefox will run in a virtual display.
# you will not see the browser.
browser = webdriver.Firefox()
browser.get('http://www.google.com')
print browser.title
browser.quit()
display.stop()

Running Selenium/PhantomJS inside a Vagrant box

I'm trying to set up testing for a Web app using behaving, which runs on top of behave and splinter - the latter of which in turn uses Selenium to drive PhantomJS. All of this is inside a VirtualBox-provided Vagrant box running CentOS 6.4. I've installed Selenium via pip, and I've installed PhantomJS from the Nux Dextop repo.
Trying to run my tests freezes Behave for 30 seconds, then raises:
selenium.common.exceptions.WebDriverException: Message: 'Can not connect to GhostDriver'
I think I've nailed it down to not being able to open a socket, and indeed, when I try to do this from the Python interactive shell, I can't open any socket to localhost at all. How do I get my tests to run?
I just had the same problem with the Can not connect to GhostDriver error. When trying phantomjs --help, I got the error
[WARNING] Unable to load library icui18n "Cannot load library icui18n: (libicui18n.so.48: cannot open shared object file: No such file or directory)"
After installing libicu48 (Ubuntu package), phantomjs --help gave me
[WARNING] phantomjs: cannot connect to X server
This made sense, since I didn't have an X server installed. Then, I discovered that phantomjs <= 1.4 requires an X server, but >= 1.5 is pure headless. So, instead of relying on my distro's phantomjs package, I installed it using npm, and now everything works fine.
I have installed the package of libicu48 and gnome-session-fallback for the bug.
$ sudo apt-get install libicu48 gnome-session-fallback