/Users/lyon/j4p/src/xml/VendorList.java
|
1 package xml;
2
3 import java.util.Vector;
4
5 /**
6 VendorList allows you to save a list of
7 vendors to a file. The list comes from
8 YellowPages.com
9 */
10 public class VendorList {
11 // a Typical search URL is:
12 // http://www.yellowpages.com/asp/search/Searchform.asp?
13 // CategoryIDs=&CategoryPath=&ResultStart=1&ResultCount=2000&NameOnly=YES&TypeOnly=&SearchRelation=&BName=computer&
14 // SearchMethod=&SearchMethod=&SearchMethod=&SearchBy=NAME&state=CT&City=
15 String url = "http://www.yellowpages.com/yellowpages/scripts/search.dll?ep=0&sic=5545&leaf=y&errp=&SearchRadius=&qzip=&qphone=&qaddress=&query=java&qcity=milford&qstate=CT&orderby=ADSPROMINENCE&ck=&userid=1&userpw=.&uh=1,0,&ccity=milford&cstate=CT&adrVer=-1&ver=5.1";
16
17 public Vector getCsv() {
18 Vector raw = net.web.Browser.getUrl(url);
19 System.out.println("got url");
20 return toAddressList(raw);
21 }
22
23 public static Vector toAddressList(Vector in) {
24 Vector out = new Vector();
25 //search for addresses
26 for (int i = 0; i < in.size(); i++) {
27 String s = (String) in.elementAt(i);
28 if (contains(s, "Phone:"))
29 out.addElement(getAddress(in, i));
30 }
31 return out;
32 }
33
34 public static boolean contains(String s1, String s2) {
35 return s1.lastIndexOf(s1) != -1;
36 }
37
38 public static String getAddress(Vector v, int i) {
39 String s = "";
40 try {
41 for (int j = -3; j < 0; j++) {
42 s = s + "," + (String) v.elementAt(j + i);
43 }
44 } catch (Exception e) {
45 }
46 return s;
47 }
48
49 public static String vector2String(Vector raw) {
50 String s = " ";
51 for (int i = 0; i < raw.size(); i++)
52 s = s + raw.elementAt(i);
53 return s;
54 }
55
56 public static void main(String args[]) {
57 VendorList vl = new VendorList();
58 net.web.Browser.print(vl.getCsv());
59
60 }
61 }