Fórum Ubuntu CZ/SK
Ostatní => Otevřená diskuze kolem Linuxu a OSS => Téma založeno: harrys 15 Listopadu 2010, 15:36:29
-
Ahoj vsem,
poradil by mi nekdo program ktery umi ulozit danou www stranku do jpg a aby to slo ovladat pres prikazovou radku.. myslim tim nahled te stranky.. predem dekuji
-
Dobrý denm, celou stránku do JPG? Tak takový asi nenajdete....
-
nemyslim jako celou stranku obsahove, jen ta co se nacte pri zadani url.. neco jak to delal websnapr.com (nevim jestli znate) ja to i kdysi mel na serveru ale nevzpomenu si jak se to jmenovalo..
-
a co zkusit trochu zagooglit?
http://cutycapt.sourceforge.net/
-
Ono to bylo mysleno jako celou viditelnou cast stranky. Jde to za pomoci rozsireni do prohlizecu, ale vy chcete neco co je pouzitelne pres prikazovou radku.
Butete potrebovat mit nainstalovane QT a webkit. zde prikladam script ktery to co potrebujete udela. Doporucuji si pomalu projit kod, je detailne komentovan aby ste pochopil jak to funguje. Screenshot dela ve formatu png, nasledni konverzi do jpg snad zvladnete.
webkit2png.py
#!/usr/bin/env python
#
# webkit2png.py
#
# Creates screenshots of webpages using by QtWebkit.
#
# Copyright (c) 2008 Roland Tapken <roland@dau-sicher.de>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
import sys
import signal
import os
import logging
import time
from optparse import OptionParser
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import QWebPage
# Class for Website-Rendering. Uses QWebPage, which
# requires a running QtGui to work.
class WebkitRenderer(QObject):
# Initializes the QWebPage object and registers some slots
def __init__(self):
logging.debug("Initializing class %s", self.__class__.__name__)
self._page = QWebPage()
self.connect(self._page, SIGNAL("loadFinished(bool)"), self.__on_load_finished)
self.connect(self._page, SIGNAL("loadStarted()"), self.__on_load_started)
# The way we will use this, it seems to be unesseccary to have Scrollbars enabled
self._page.mainFrame().setScrollBarPolicy(Qt.Horizontal, Qt.ScrollBarAlwaysOff)
self._page.mainFrame().setScrollBarPolicy(Qt.Vertical, Qt.ScrollBarAlwaysOff)
# Helper for multithreaded communication through signals
self.__loading = False
self.__loading_result = False
# Loads "url" and renders it.
# Returns QImage-object on success.
def render(self, url, width=0, height=0, timeout=0):
logging.debug("render(%s, timeout=%d)", url, timeout)
# This is an event-based application. So we have to wait until
# "loadFinished(bool)" raised.
cancelAt = time.time() + timeout
self._page.mainFrame().load(QUrl(url))
while self.__loading:
if timeout > 0 and time.time() >= cancelAt:
raise RuntimeError("Request timed out")
QCoreApplication.processEvents()
logging.debug("Processing result")
if self.__loading_result == False:
raise RuntimeError("Failed to load %s" % url)
# Set initial viewport (the size of the "window")
size = self._page.mainFrame().contentsSize()
if width > 0:
size.setWidth(width)
if height > 0:
size.setHeight(height)
self._page.setViewportSize(size)
# Paint this frame into an image
image = QImage(self._page.viewportSize(), QImage.Format_ARGB32)
painter = QPainter(image)
self._page.mainFrame().render(painter)
painter.end()
return image
# Eventhandler for "loadStarted()" signal
def __on_load_started(self):
logging.debug("loading started")
self.__loading = True
# Eventhandler for "loadFinished(bool)" signal
def __on_load_finished(self, result):
logging.debug("loading finished with result %s", result)
self.__loading = False
self.__loading_result = result
if __name__ == '__main__':
# Parse command line arguments.
# Syntax:
# $0 [--xvfb|--display=DISPLAY] [--debug] [--output=FILENAME] <URL>
qtargs = [sys.argv[0]]
description = "Creates a screenshot of a website using QtWebkit." \
+ "This program comes with ABSOLUTELY NO WARRANTY. " \
+ "This is free software, and you are welcome to redistribute " \
+ "it under the terms of the GNU General Public License v2."
parser = OptionParser(usage="usage: %prog [options] <URL>",
version="%prog 0.1, Copyright (c) 2008 Roland Tapken",
description=description)
parser.add_option("-x", "--xvfb", action="store_true", dest="xvfb",
help="Start an 'xvfb' instance.", default=False)
parser.add_option("-g", "--geometry", dest="geometry", nargs=2, default=(0, 0), type="int",
help="Geometry of the virtual browser window (0 means 'autodetect') [default: %default].", metavar="WIDTH HEIGHT")
parser.add_option("-o", "--output", dest="output",
help="Write output to FILE instead of STDOUT.", metavar="FILE")
parser.add_option("-f", "--format", dest="format", default="png",
help="Output image format [default: %default]", metavar="FORMAT")
parser.add_option("--scale", dest="scale", nargs=2, type="int",
help="Scale the image to this size", metavar="WIDTH HEIGHT")
parser.add_option("--aspect-ratio", dest="ratio", type="choice", choices=["ignore", "keep", "expand"],
help="One of 'ignore', 'keep' or 'expand' [default: %default]")
parser.add_option("-t", "--timeout", dest="timeout", default=0, type="int",
help="Time before the request will be canceled [default: %default]", metavar="SECONDS")
parser.add_option("-d", "--display", dest="display",
help="Connect to X server at DISPLAY.", metavar="DISPLAY")
parser.add_option("--debug", action="store_true", dest="debug",
help="Show debugging information.", default=False)
# Parse command line arguments and validate them (as far as we can)
(options,args) = parser.parse_args()
if len(args) != 1:
parser.error("incorrect number of arguments")
if options.display and options.xvfb:
parser.error("options -x and -d are mutually exclusive")
options.url = args[0]
# Enable output of debugging information
if options.debug:
logging.basicConfig(level=logging.DEBUG)
# Add display information for qt (you may also use the environment var DISPLAY)
if options.display:
qtargs.append("-display")
qtargs.append(options.display)
if options.xvfb:
# Start 'xvfb' instance by replacing the current process
newArgs = ["xvfb-run", "--server-args=-screen 0, 640x480x24", sys.argv[0]]
for i in range(1, len(sys.argv)):
if sys.argv[i] not in ["-x", "--xvfb"]:
newArgs.append(sys.argv[i])
logging.debug("Executing %s" % " ".join(newArgs))
os.execvp(newArgs[0], newArgs)
raise RuntimeError("Failed to execute '%s'" % newArgs[0])
# Prepare outout ("1" means STDOUT)
if options.output == None:
qfile = QFile()
qfile.open(1, QIODevice.WriteOnly)
options.output = qfile
# Initialize Qt-Application, but make this script
# abortable via CTRL-C
app = QApplication(qtargs)
signal.signal(signal.SIGINT, signal.SIG_DFL)
# Initialize WebkitRenderer object
renderer = WebkitRenderer()
# Technically, this is a QtGui application, because QWebPage requires it
# to be. But because we will have no user interaction, and rendering can
# not start before 'app.exec_()' is called, we have to trigger our "main"
# by a timer event.
def __on_exec():
# Render the page.
# If this method times out or loading failed, a
# RuntimeException is thrown
try:
image = renderer.render(options.url,
width=options.geometry[0],
height=options.geometry[1],
timeout=options.timeout)
if options.scale:
# Scale this image
if options.ratio == 'keep':
ratio = Qt.KeepAspectRatio
elif options.ratio == 'expand':
ratio = Qt.KeepAspectRatioByExpanding
else:
ratio = Qt.IgnoreAspectRatio
image = image.scaled(options.scale[0], options.scale[1], ratio)
image.save(options.output, options.format)
if isinstance(options.output, QFile):
options.output.close()
sys.exit(0)
except RuntimeError, e:
logging.error(e.message)
sys.exit(1)
# Go to main loop (required)
QTimer().singleShot(0, __on_exec)
sys.exit(app.exec_())
Odkaz na autora pro vice info: http://www.blogs.uni-osnabrueck.de/rotapken/2008/12/03/create-screenshots-of-a-web-page-using-python-and-qtwebkit/ (http://www.blogs.uni-osnabrueck.de/rotapken/2008/12/03/create-screenshots-of-a-web-page-using-python-and-qtwebkit/)
-
Už rozumím, nevím.
-
a co zkusit trochu zagooglit?
http://cutycapt.sourceforge.net/
souhlas, cuttycap take funguje prakticky za pouziti xvfb framebufferu
-
.................
Butete potrebovat mit nainstalovane QT a webkit.
...............
anglicky sice neumim ale predpoladam ze musim mit nainstalovane GUI ?
diky
-
Ach jo ....
potrebujete mit nasledujici baliky: libqt4-webkit , python-qt4, webkit, xvfb
takze:
sudo apt-get install libqt4-webkit python-qt4 webkit xvfb
a zde mate priklad pouziti:
xvfb-run --server-args="-screen 0, 640x480x24" python webkit2png.py http://www.ubuntu.cz -o /home/petrakis/Desktop/test.png
[attachment deleted by admin]
-
souhlas, cuttycap take funguje prakticky za pouziti xvfb framebufferu
o xvfb framebufferu jsem neco cetl, jestli se nepletu tak je to nejaka virtualni nahrada aby se desktop nemusel instalovat, je tomu tak?
-
...
o xvfb framebufferu jsem neco cetl, jestli se nepletu tak je to nejaka virtualni nahrada aby se desktop nemusel instalovat, je tomu tak?
jak rikal major Terazky - povězte mi, čo si představujete pod takým pojmem "desktop"?
-
jak rikal major Terazky - povězte mi, čo si představujete pod takým pojmem "desktop"?
no myslim tim desktopove prostredi.. ;)
-
Tak jsem to zkousel nainstalovat, ale skoncil jsem touto hlaskou..
debian:~# apt-get install webkit
Čtu seznamy balíků... Hotovo
Vytvářím strom závislostí
Čtu stavové informace... Hotovo
E: Nemohu najít balík webkit
debian:~#
poradite prosim jak to vyresit?
dekuji
-
nikdo nevite? :'(
-
apt-get install cutycapta je to
-
hm, ten stejny problem..
debian:/aaa# apt-get install cutycapt
Čtu seznamy balíků... Hotovo
Vytvářím strom závislostí
Čtu stavové informace... Hotovo
E: Nemohu najít balík cutycapt
debian:/aaa#
ale proc?
-
Aha, v sidu už to je. V tom případě postupuj podle instrukcí dole na http://cutycapt.sourceforge.net/
-
diky moc, jdu na to hned mrknout ale porad jeste nevim jestli na to potrebuji nainstalovane to desktopove prostredi nebo jen instalace serveru staci.. :-\
-
Using CutyCapt without X server
You cannot use CutyCapt without an X server, but you can use e.g. Xvfb as light-weight server if you are not running an interactive graphical desktop environment. For example, you could use:
% xvfb-run --server-args="-screen 0, 1024x768x24" ./CutyCapt --url=... --out=...
-
uf tak to je super.. uz to chodi akorat nevim nejake podrobnejsi nastaveni kde hledat..
-
žeby man cutycapt ? :)
-
to jsem zkousel.. to jedine znam ;D ale pise to ze manual zadny neni..
debian:/aaa/cutycapt/CutyCapt# man cutycapt
No manual entry for cutycapt
debian:/aaa/cutycapt/CutyCapt#
-
tak cutycapt --help, to už jít musí
-
Tak jsem to zkousel nainstalovat, ale skoncil jsem touto hlaskou..
debian:~# apt-get install webkit
Čtu seznamy balíků... Hotovo
Vytvářím strom závislostí
Čtu stavové informace... Hotovo
E: Nemohu najít balík webkit
debian:~#
poradite prosim jak to vyresit?
dekuji
nemuzu si pomoci ale clovek ti da na podnosu script, reseni, napise ti co si mas nainstalovat a ty to ignorujes a divis se ze nemas webkit. Uz jednoduseji jsem nemohl napsat co si mas instalovat aby jsi ten script mohl spustit
Ach jo ....
potrebujete mit nasledujici baliky: libqt4-webkit , python-qt4, webkit, xvfb
takze:
sudo apt-get install libqt4-webkit python-qt4 webkit xvfb
a zde mate priklad pouziti:
xvfb-run --server-args="-screen 0, 640x480x24" python webkit2png.py http://www.ubuntu.cz -o /home/petrakis/Desktop/test.png
-
potrebujete mit nasledujici baliky: libqt4-webkit , python-qt4, webkit, xvfb
takze:
sudo apt-get install libqt4-webkit python-qt4 webkit xvfb
tak jsem to presne udelal jak jste mi radil, vsechno se nainstalovalo krome toho balicku webkit
ten prave skoncil tou chybou ze ho nemuze najit.. ty ostatni tri balicky se nainstalovaly..
-
tak cutycapt --help, to už jít musí
nejde to ani ted.. neco jsem nasel na tech strankach co jste dal ten link ale nikde tam nevidim jedno zakladni (celkem dost dulezite) kvalita toho obrazku a velikost toho obrazku, kdyz jsou stranky dlouhe tak se udela ne obrazek o dane velikosti ale treba takova dlouha nudle..
-
potrebujete mit nasledujici baliky: libqt4-webkit , python-qt4, webkit, xvfb
takze:
sudo apt-get install libqt4-webkit python-qt4 webkit xvfb
tak jsem to presne udelal jak jste mi radil, vsechno se nainstalovalo krome toho balicku webkit
ten prave skoncil tou chybou ze ho nemuze najit.. ty ostatni tri balicky se nainstalovaly..
s prominutim ale kdyz neco instaluji tak se koukam co se mi instaluje, a kdyz se nenainstaloval a vyhodi mi hlasku ze chybi webkit tak si jej nainstaluji. Uz zde bylo castokrat zmineno pouzivat wiki pokud jste uplny zacatecnik. Nic to vsak, udelejte to jak jsem vam to napsal a pouzijte ten prikaz co jsem postnul, kvalita se urcuje parametrem 640x480x24 (btw. kdyby jste se kouknul trochu do toho scriptu tak by jste mnohe pochopil)
Pracovat na jakemkoliv Linuxovem systemu znamena take snahu cosi o kodu vedet