Filters: Advanced
See also: The FAQ
You have to know that once you have defined
starts links, the default mode is to mirror these links - i.e. if one of your start page is
www.someweb.com/test/index.html, all links starting with www.someweb.com/test/ will be
accepted. But links directly in www.someweb.com/.. will not be accepted, however, because
they are in a higher strcuture. This prevent HTTrack from mirroring the whole site. (All
files in structure levels equal or lower than the primary links will be retrieved.)
But you may want to download files that are not directly in the subfolders, or on the
contrary refuse files of a particular type. That is the purpose of filters.
Scan rules based on URL or extension (e.g. accept or refuse all .zip or .gif files)
To accept a family of links (for example, all links with a specific name or type), you just have to add
an authorization filter, like +*.gif. The pattern is a plus (this one: +),
followed by a pattern composed of letters and wildcards (this one: *).
To forbide a family of links, define
an authorization filter, like -*.gif. The pattern is a dash (this one: -),
followed by a the same kind of pattern as for the authorization filter.
Example: +*.gif will accept all files finished by .gif
Example: -*.gif will refuse all files finished by .gif
Scan rules based on size (e.g. accept or refuse files bigger/smaller than a certain size)
Once a link is scheduled for download, you can still refuse it (i.e. abort the download) by checking its
size to ensure that you won't reach a defined limit.
Example: You may want to accept all files on the domain www.example.com, using '+www.example.com/*',
including gif files inside this domain and outside (eternal images), but not take to large images,
or too small ones (thumbnails)
Excluding gif images smaller than 5KB and images larger than 100KB is therefore a good option;
+www.example.com +*.gif -*.gif*[<5] -*.gif*[>100]
Important notice: size scan rules are checked after the link was scheduled for download,
allowing to abort the connection.
Scan rules based on MIME types (e.g. accept or refuse all files of type audio/mp3)
Once a link is scheduled for download, you can still refuse it (i.e. abort the download) by matching its MIME
type against certain patterns.
Example: You may want to accept all files on the domain www.example.com, using '+www.example.com/*', and
exclude all gif files, using '-*.gif'. But some dynamic scripts (such as www.example.com/dynamic.php) can
both generate html content, or image data content, depending on the context. Excluding this script, using
the scan rule '-www.example.com/dynamic.php', is therefore not a good solution.
The only reliable way in such cases is to exclude the specific mime type 'image/gif', using the scan rule
syntax:
-mime:image/gif
Important notice: MIME types scan rules are only checked against links that were
scheduled for download, i.e. links already authorized by url scan rules.
Hence, using '+mime:image/gif' will only be a hint to accept images that were already authorized,
if previous MIME scan rules excluded them - such as in '-mime:*/* +mime:text/html +mime:image/gif'
Scan rules patterns:
1.a. Scan rules based on URL or extension
Filters are analyzed by HTTrack from the first filter to the last one. The complete URL
name is compared to filters defined by the user or added automatically by HTTrack.
A scan rule has an higher priority is it is declared later - hierarchy is important:
+*.gif -image*.gif
|
Will accept all gif files BUT image1.gif,imageblue.gif,imagery.gif and so on
|
-image*.gif +*.gif
|
Will accept all gif files, because the second pattern is prioritary (because it is defined AFTER the first one)
|
Note: these scan rules can be mixed with scan rules based on size (see 1.b)
We saw that patterns are composed of letters and wildcards (*), as in */image*.gif
Special wild cards can be used for specific characters: (*[..])
* |
any characters (the most commonly used) |
*[file] or *[name] |
any filename or name, e.g. not /,? and ; characters |
*[path] |
any path (and filename), e.g. not ? and ; characters |
*[a,z,e,r,t,y] |
any letters among a,z,e,r,t,y |
*[a-z] |
any letters |
*[0-9,a,z,e,r,t,y] |
any characters among 0..9 and a,z,e,r,t,y |
*[\*] |
the * character |
*[\\] |
the \ character |
*[\[\]] |
the [ or ] character |
*[] |
no characters must be present after |
Here are some examples of filters: (that can be generated automatically using the
interface)
www.thisweb.com* |
This will refuse/accept this web site (all links located in it will be rejected) |
*.com/* |
This will refuse/accept all links that contains .com in them |
*cgi-bin* |
This will refuse/accept all links that contains cgi-bin in them |
www.*[path].com/*[path].zip |
This will refuse/accept all zip files in .com addresses |
*someweb*/*.tar* |
This will refuse/accept all tar (or tar.gz etc.) files in hosts containing someweb |
*/*somepage* |
This will refuse/accept all links containing somepage (but not in the address) |
*.html |
This will refuse/accept all html files.
Warning! With this filter you will accept ALL html files, even those in other addresses.
(causing a global (!) web mirror..) Use www.someweb.com/*.html to accept all html files from
a web. |
*.html*[] |
Identical to *.html, but the link must not have any supplemental characters
at the end (links with parameters, like www.someweb.com/index.html?page=10, will be
refused) |
1.b. Scan rules based on size
Filters are analyzed by HTTrack from the first filter to the last one. The sizes
are compared against scan rules defined by the user.
A scan rule has an higher priority is it is declared later - hierarchy is important.
Note: scan rules based on size can be mixed with regular URL patterns
Size patterns:
*[<NN] |
the file size must be smaller than NN KB
(note: this may cause broken files during the download) |
*[>NN] |
the file size must be greater than NN KB
(note: this may cause broken files during the download) |
*[<NN>MM] |
the file size must be smaller than NN KB and greater than MM KB
(note: this may cause broken files during the download) |
Here are some examples of filters: (that can be generated automatically using the
interface)
-*[<10] |
the file will be forbidden if its size is smaller than 10 KB |
-*[>50] |
the file will be forbidden if its size is greater than 50 KB |
-*[<10] -*[>50] |
the file will be forbidden if if its size is smaller than 10 KB or greater than 50 KB |
+*[<80>1] |
the file will be accepted if if its size is smaller than 80 KB and greater than 1 KB |
2. Scan rules based on MIME types
Filters are analyzed by HTTrack from the first filter to the last one. The complete MIME
type is compared against scan rules defined by the user.
A scan rule has an higher priority is it is declared later - hierarchy is important
Note: scan rules based on MIME types can NOT be mixed with regular URL patterns or size patterns within the same rule, but you can use both of them in distinct ones
Here are some examples of filters: (that can be generated automatically using the
interface)
-mime:application/octet-stream |
This will refuse all links of type 'application/octet-stream' that were already scheduled for download
(i.e. the download will be aborted) |
-mime:application/* |
This will refuse all links of type begining with 'application/' that were already scheduled for download
(i.e. the download will be aborted) |
-mime:application/* +mime:application/pdf |
This will refuse all links of type begining with 'application/' that were already scheduled for download, except for 'application/pdf' ones
(i.e. all other 'application/' link download will be aborted) |
-mime:video/* |
This will refuse all video links that were already scheduled for download
(i.e. all other 'application/' link download will be aborted) |
-mime:video/* -mime:audio/* |
This will refuse all audio and video links that were already scheduled for download
(i.e. all other 'application/' link download will be aborted) |
-mime:*/* +mime:text/html +mime:image/* |
This will refuse all links that were already scheduled for download, except html pages, and images
(i.e. all other link download will be aborted). Note that this is a very unefficient way of filtering
files, as aborted downloads will generate useless requests to the server. You are strongly advised to
use additional URL scan rules |
2. Scan rules based on URL or size, and scan rules based on MIME types interactions
You must use scan rules based on MIME types very carefully, or you will end up with an imcomplete
mirror, or create an unefficient download session (generating costly and useless requests to the server)
Here are some examples of good/bad scan rules interactions:
Purpose |
Method |
Result |
Download all html and images on www.example.com |
-* +www.example.com/*.html +www.example.com/*.php +www.example.com/*.asp +www.example.com/*.gif +www.example.com/*.jpg +www.example.com/*.png -mime:*/* +mime:text/html +mime:image/* |
Good: efficient download |
-* +www.example.com/* -mime:*/* +mime:text/html +mime:image/* |
Bad: many aborted downloads, leading to poor performances and server load |
Download only html on www.example.com, plus ZIP files |
-* +www.example.com/*.html +www.example.com/somedynamicscript.php +www.example.com/*.zip -mime:* +mime:text/html +mime:application/zip |
Good: ZIP files will be downloaded, even those generated by 'somedynamicscript.php' |
-* +www.example.com/*.html -mime:* +mime:text/html +mime:application/zip |
Bad: ZIP files will never be scheduled for download, and hence the zip mime scan rule will never be used |
Download all html, and images smaller than 100KB on www.example.com |
-* +www.example.com/*.html +www.example.com/*.php +www.example.com/*.asp +www.example.com/*.gif*[<100] +www.example.com/*.jpg*[<100] +www.example.com/*.png*[<100] -mime:*/* +mime:text/html +mime:image/* |
Good: efficient download |
-* +www.example.com/**[<100] -mime:*/* +mime:text/html +mime:image/* |
Bad: many aborted downloads, leading to poor performances and server load |
|