How to Take Screenshots of Web Pages Using Ruby and a Unix Server

How do I take screenshots of web pages using ruby and a unix server?

Selenium RC has a Ruby interface and can grab a screenshot using capture_screenshot(filename,kwargs).

You'd then have to shrink it to a thumbnail.

Click on Print gives a screen shot to save in rails3

You could go for phantomJs. Where you can alter the page HTML, manipulate CSS, insert & call javascript snippets, the way you need it.

Good documentation available and also you can find great deal of help in stackoverflow-phantomjs

Regards,

HBK

Extracting background-images from a web page / Parsing HTML+CSS

When you parse the CSS of a web site, any images you are going to get back are going to be related to the user interface (sprites, backgrounds), not the actual content of the page.

I don't think it would be worth your while unless you're just trying to extract logos. In that case I would restrict to matches on class names/ids/paths containing the word "logo".

If you want to extract "representative images" from a page, I would just parse the image tags as you are doing then generate (and crop) a screenshot of the page as per: How do I take screenshots of web pages using ruby and a unix server?

How are you handling images that aren't in the raw HTML source?

In terms of libraries, I'm pretty sure nokogiri is the best thing out there.

How can I take a screenshot with Selenium WebDriver?

Java

Yes, it is possible. The following example is in Java:

WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com/");
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
// Now you can do whatever you need to do with it, for example copy somewhere
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));

Rails static images not showing up

Fix webapp_healthd.conf to make nginx to serve files in public folder and if cannot or they do not exist then proxy_pass to Your app:

upstream my_app {
server unix:///var/run/puma/my_app.sock;
}

server {
listen 80;
server_name _; # need to listen to localhost for worker tier

if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") {
set $year $1;
set $month $2;
set $day $3;
set $hour $4;
}

access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour healthd;

index index.html index.htm;

location @app {
log_not_found off;
access_log off;
proxy_pass http://my_app; # proxy passing to upstream
proxy_http_version 1.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_cache_bypass $http_upgrade;
}

root /var/app/current/public;

location / {
try_files $uri $uri/ @app; # tries to serve static files if not will ask @app
}
}


Related Topics



Leave a reply



Submit