1 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 """Command for scraping images from a URL or list of URLs.
8 1. The command_line package from tools/site_compare
9 2. Either the IE BHO or Firefox extension (or both)
12 1. Build the IE BHO, or call regsvr32 on a prebuilt binary
13 2. Add a file called "measurepageloadtimeextension@google.com" to
14 the default Firefox profile directory under extensions, containing
15 the path to the Firefox extension root
17 Invoke with the command line arguments as documented within
23 from drivers
import windowing
24 from utils
import browser_iterate
26 def CreateCommand(cmdline
):
27 """Inserts the command and arguments into a command line for parsing."""
28 cmd
= cmdline
.AddCommand(
30 "Scrapes an image from a URL or series of URLs.",
34 browser_iterate
.SetupIterationCommandLine(cmd
)
36 ["-log", "--logfile"], "File to write text output", type="string")
38 ["-out", "--outdir"], "Directory to store scrapes", type="string", required
=True)
41 def ExecuteScrape(command
):
42 """Executes the Scrape command."""
44 def ScrapeResult(url
, proc
, wnd
, result
):
45 """Capture and save the scrape."""
46 if log_file
: log_file
.write(result
)
49 image
= windowing
.ScrapeWindow(wnd
)
50 filename
= windowing
.URLtoFilename(url
, command
["--outdir"], ".bmp")
53 if command
["--logfile"]: log_file
= open(command
["--logfile"], "w")
56 browser_iterate
.Iterate(command
, ScrapeResult
)
58 # Close the log file and return. We're done.
59 if log_file
: log_file
.close()