1 package org.wamblee.crawler.impl;
4 import java.io.FileInputStream;
5 import java.io.FileOutputStream;
6 import java.io.InputStream;
7 import java.io.PrintStream;
9 import org.apache.commons.httpclient.HttpClient;
10 import org.dom4j.Element;
11 import org.wamblee.crawler.Action;
12 import org.wamblee.crawler.Configuration;
13 import org.wamblee.crawler.Crawler;
14 import org.wamblee.crawler.Page;
17 * Copyright 2005 the original author or authors.
19 * Licensed under the Apache License, Version 2.0 (the "License");
20 * you may not use this file except in compliance with the License.
21 * You may obtain a copy of the License at
23 * http://www.apache.org/licenses/LICENSE-2.0
25 * Unless required by applicable law or agreed to in writing, software
26 * distributed under the License is distributed on an "AS IS" BASIS,
27 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28 * See the License for the specific language governing permissions and
29 * limitations under the License.
33 * Entry point for the crawler.
37 private static final String LOG_FILE = "crawler.log";
39 public static void main(String[] args) throws Exception {
40 String configFileName = args[0];
41 String starturl = args[1];
43 FileOutputStream fos = new FileOutputStream(new File(LOG_FILE));
44 PrintStream os = new PrintStream(fos);
47 ConfigurationParser parser = new ConfigurationParser(os);
48 InputStream configFile = new FileInputStream(new File(
50 Configuration config = parser.parse(configFile);
52 HttpClient client = new HttpClient();
53 // client.getHostConfiguration().setProxy("localhost", 3128);
55 Crawler crawler = new CrawlerImpl(client, config);
57 System.out.println("Retrieving: " + starturl);
58 Page page = crawler.getPage(starturl);
60 page = page.getAction("channels-favorites").execute();
61 recordInterestingShows(page);
63 page = page.getAction("Nederland 1").execute();
65 page = page.getAction("right-now").execute();
67 page = page.getAction("Het elfde uur").execute();
72 System.out.println("Output written on '" + LOG_FILE + "'");
80 private static void showPage(Page aPage) {
81 Action[] links = aPage.getActions();
82 for (Action link: links) {
83 System.out.println("Link found '" + link.getName() + "'");
85 Element element = aPage.getContent();
86 System.out.println("Retrieved content: " + element.asXML());
89 private static void recordInterestingShows(Page page) {
90 Action[] channels = page.getActions();
91 for (Action channel: channels) {
92 examineChannel(channel.getName(), channel.execute().getAction("right-now").execute());
96 private static void examineChannel(String aChannel, Page aPage) {
97 Action[] programs = aPage.getActions();
98 for (Action program: programs) {
99 System.out.println(aChannel + " - " + program.getName());
100 if ( program.getName().toLowerCase().matches(".*babe.*")) {
101 Page programPage = program.execute();
102 Action record = programPage.getAction("record");
103 System.out.println("Recording possible: " + record != null);