1 package org.paneris.bibliomania.metasearch.amazon;
2
3 import java.io.File;
4
5 import org.melati.util.IoUtils;
6 import org.paneris.bibliomania.BookStocking;
7 import org.paneris.bibliomania.metasearch.BookStockingFactory;
8 import org.paneris.bibliomania.metasearch.util.SearchResultsBase;
9
10 public class SearchResults extends SearchResultsBase {
11
12 protected static final byte[]
13 resultsSortedBy = "<div id=\"Results\" class=\"n2\">".getBytes(),
14 obidosASIN = "/dp/".getBytes(),
15 brBy = "</span></a>\n \n by ".getBytes(),
16 dotNL = ".\n".getBytes(),
17 spc3 = " ".getBytes(),
18 spc2 = " ".getBytes(),
19 slashTD = "</td>".getBytes(),
20 fontColor990000 = "<font color=#990000>".getBytes();
21
22 public SearchResults(byte[] text,
23 BookStockingFactory stockings) {
24 super(text, stockings);
25 skipTo(resultsSortedBy);
26 }
27
28 protected Object more() {
29 try {
30 for (;;) {
31 skipTo(obidosASIN);
32 skipTo(obidosASIN);
33 try {
34 BookStocking bookStocking = stockings.newStocking();
35
36 bookStocking.setIsbn_unsafe(digits());
37 bookStocking.setVendorproductid_unsafe(bookStocking.getIsbn_unsafe());
38
39
40 bookStocking.setDetailurl_unsafe("");
41
42 skipTo("\"srTitle\">".getBytes());
43 bookStocking.setTitle_unsafe(plaintext());
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71 System.err.println("Returning " + bookStocking);
72 return bookStocking;
73 }
74 catch (ParseException e) {
75 System.err.println(e);
76
77 }
78 }
79 }
80 catch (ArrayIndexOutOfBoundsException e) {
81 System.err.println(e);
82 }
83 catch (ParseException e) {
84 System.err.println(e);
85 }
86
87 return null;
88 }
89
90 public static void main(String[] args) throws Exception {
91 BookStockingFactory dummy =
92 new BookStockingFactory() {
93 public BookStocking newStocking() {
94 return new BookStocking();
95 }
96 };
97
98 SearchResults r = new SearchResults(IoUtils.slurp(new File(args[0]), 1000),
99 dummy);
100 while (r.hasMoreElements())
101 ((BookStocking)r.nextElement()).dump(System.out);
102 }
103 }