/ Published in: Java
version 17. 9/29/2011
Expand |
Embed | Plain Text
package com.mktneutral; import java.io.IOException; import java.util.List; import java.util.ArrayList; import java.util.HashMap; import java.sql.Connection; import java.sql.Statement; import java.sql.DriverManager; import java.sql.SQLException; import java.net.URL; import java.net.MalformedURLException; import java.net.HttpURLConnection; import java.net.URLEncoder; import java.io.OutputStreamWriter; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.OutputStream; import java.util.regex.Pattern; import org.htmlparser.Parser; import org.htmlparser.Node; import org.htmlparser.util.NodeList; import org.htmlparser.util.ParserException; public class GovAuctions { private static HashMap<String,String> stateMap; } try { Class.forName("org.hsqldb.jdbcDriver"); String[] stateNameList = { "Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "District of Columbia", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming", "American Samoa", "Guam", "Northern Mariana Islands", "Puerto Rico" }; String[] stateAbbrevList = { "AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY", "AS", "GU", "MP", "PR" }; stateMap = new HashMap<String,String>(); for ( int i=0; i<stateNameList.length; i++ ) { stateMap.put( stateAbbrevList[i], stateNameList[i] ); } hsql = null; try { } try { stmt = hsql.createStatement(); stmt.executeUpdate( "DROP TABLE IF EXISTS auction_records" ); stmt.executeUpdate( "CREATE TABLE auction_records ( website VARCHAR(64), url VARCHAR(1024), results_content VARCHAR(1536) )" ); searchState = _searchState; searchString = _searchString; responseData = ""; if ( searchEngineInt == 0 ) { GovLiquidation(); } if ( searchEngineInt == 1 ) { GSAAuctions(); } if ( searchEngineInt == 2 ) { IRSAuctions(); } if ( searchEngineInt == 3 ) { BidCorp(); } if ( searchEngineInt == 4 ) { bid4Assets(); } if ( searchEngineInt == 5 ) { BankruptcySales(); } if ( searchEngineInt == 6 ) { PublicSurplus(); } if ( searchEngineInt == 7 ) { GovernmentAuction(); } if ( searchEngineInt == 8 ) { HomeSteps(); } if ( searchEngineInt == 9 ) { HomePath(); } if ( searchEngineInt == 10 ) { HomeSalesGov(); } if ( searchEngineInt == 17 ) { HudHomeStore(); } if ( searchEngineInt == 11 ) { GSAGov(); } if ( searchEngineInt == 12 ) { GovSales(); } if ( searchEngineInt == 13 ) { LonestarOnline(); } if ( searchEngineInt == 14 ) { GovDeals(); } if ( searchEngineInt == 15 ) { IllinoisIbid(); } if ( searchEngineInt == 16 ) { PropertyRoom(); } try { hsql.close(); } return responseData; } public static void GovLiquidation() { if ( !searchState.equals("ALL") ) { ntt = "US_" + searchState + "|" + searchString; location = "&location=US_" + searchState; ntk = "P_Auction_Country_State|P_Lot_Title"; } else { ntt = searchString; location = ""; ntk = "P_Lot_Title"; } String message = "Ntt=" + ntt + "&Ntk=" + ntk + "&Ntx=mode+matchall|mode+matchall&N=0&Nty=1&Ns=P_Lot_Number|0" + location + "&words=" + searchString + "&cmd=keyword"; try { String line; while ((line = reader.readLine()) != null) { resp += line; } reader.close(); int startIdx = resp.indexOf("<TABLE CELLSPACING=\"0\" CELLPADDING=\"0\" border=\"0\" WIDTH=\"748\" ALIGN=\"CENTER\" id=\"lots_table\">"); int endIdx = resp.indexOf("<!-- Load the Brightcove JavaScript API -->"); if ( endIdx > 0 && startIdx > 0 ) { try { htmlParser.setInputHTML( resp.substring( startIdx, endIdx ) ); NodeList nList = htmlParser.parse(null); if ( nList.size() > 0 ) { NodeList trList = nList.elementAt(0).getChildren(); for ( int i=0; i<trList.size(); i++ ) { if ( trList.elementAt(i).getText().contains("resultsBackground1") || trList.elementAt(i).getText().contains("resultsBackground2") ) { NodeList tdList = trList.elementAt(i).getChildren(); for ( int j=0; j<tdList.size(); j++ ) { if ( (tdList.elementAt(j).getText()).trim().equals("TD VALIGN=\"top\" class=\"annotationText1\"") ) { resultsContent = resultsContent.replaceAll("\"", "'" ); resultsContent = resultsContent.replaceAll("\n", ""); resultsContent = resultsContent.replaceAll("\t", ""); NodeList aList = tdList.elementAt(j).getChildren(); for ( int k=0; k<aList.size(); k++ ) { if ( aList.elementAt(k).getText().contains("A HREF=\"http://www.govliquidation.com/auction/view") ) { anchorHref = pieces[1].trim(); try { System.out.println( "INSERT INTO auction_records ( website, url, results_content ) VALUES ( 'http://www.govliquidation.com/', '" + anchorHref + "', '" + resultsContent + "' )" ); stmt.executeUpdate( "INSERT INTO auction_records ( website, url, results_content ) VALUES ( 'http://www.govliquidation.com/', '" + anchorHref + "', '" + resultsContent + "' )" ); } } } } } } } } catch ( ParserException pe ) { pe.printStackTrace(); } } } public static void GSAAuctions() { if ( searchState.equals("ALL") ) { try { conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); conn.setRequestProperty("User-Agent","Mozilla/5.0"); os.write(message.getBytes("UTF-8")); os.close(); String line; while ((line = myReader.readLine()) != null) { resp += line; } myReader.close(); int scIdx = resp.indexOf("name=\"scParam\" VALUE=\""); if ( scIdx > 0 ) { if ( pieces.length > 1 ) { int webPcmIdx = resp.indexOf("name=\"WEBPCMTRANSID\" VALUE=\""); if ( webPcmIdx > 1 ) { pieces = resp.substring( webPcmIdx+10, webPcmIdx+80 ).split("VALUE=\""); if ( pieces.length > 0 ) { piecesII = pieces[1].split("\""); String msg2 = "scParam=" + URLEncoder.encode(scParam) + "&WEBPCMTRANSID=" + URLEncoder.encode( webPcmParam ) + "&sc=&scAction=" + URLEncoder.encode("AUCALSRH") + "&scRegn=&scSalNo=&scLotNo=&scQuery=&query=&order=&af2eq=&scCatCode=&scStCode=&scPassUpd=&scSrchDesc=" + URLEncoder.encode( searchString ) + "&scSrchDescCtxt=&catMenuNew="; con2.setDoOutput(true); con2.setRequestMethod("POST"); con2.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); con2.setRequestProperty("User-Agent","Mozilla/5.0"); writer.write(msg2.getBytes("UTF-8")); writer.close(); line = ""; resp = ""; while ((line = leer.readLine()) != null) { resp += line; } leer.close(); int startIdx = resp.indexOf("var tab=["); int endIdx = resp.indexOf("bldTr();"); pieces = resp.substring( startIdx, endIdx ).split(Pattern.quote("[")); if ( pieces.length > 1 ) { piecesII = pieces[1].split(Pattern.quote("]")); pieces = piecesII[0].split("\",\""); if ( pieces.length > 6 ) { for ( int j=0; j<pieces.length; j+=7 ) { resultsContent = pieces[j].replace("\"","") + " " + pieces[j+1] + " " + pieces[j+2] + " " + pieces[j+3] + " " + pieces[j+4] + " " + pieces[j+5] + " " + pieces[j+6].replace("\",",""); anchorHref = "javascript:itemSel('" + pieces[j+1].substring(0,11) + "','" + pieces[j+1].substring(11) + "');"; try { stmt.executeUpdate( "INSERT INTO auction_records ( website, url, results_content ) VALUES ( 'http://gsaauctions.gov/', '" + anchorHref + "', '" + resultsContent + "' )" ); } } } } } } } } } public static void IRSAuctions() { if ( searchState.equals("ALL") ) { try { URL theUrl = new URL("http://search.treas.gov/search?q=" + URLEncoder.encode(searchString) + "&output=xml_no_dtd&sort=date%3AD%3AL%3Ad1&ie=UTF-8&client=auctions&oe=UTF-8&proxystylesheet=auctions&site=Auctions"); String line; while ((line = reader.readLine()) != null) { resp += line; } reader.close(); int startIdx = resp.indexOf("<p><font size=\"-2\">"); int endIdx = resp.indexOf("In order to show you"); if ( startIdx > 0 && endIdx > startIdx ) { try { htmlParser.setInputHTML( resp.substring(startIdx,endIdx) ); NodeList nList = htmlParser.parse(null); for ( int i=0; i<nList.size(); i++ ) { if ( nList.elementAt(i).getText().startsWith("p") ) { NodeList pChildList = nList.elementAt(i).getChildren(); for ( int j=0; j<pChildList.size(); j++ ) { if ( pChildList.elementAt(j).getText().startsWith("a href=\"http://www.treasury") ) { anchorHref = pieces[1].trim(); } if ( pChildList.elementAt(j).getText().startsWith("span class=\"s\"") ) { resultsContent = resultsContent.replaceAll("\"", ""); resultsContent = resultsContent.replaceAll("\n", ""); try { stmt.executeUpdate( "INSERT INTO auction_records VALUES ( 'http://search.treas.gov/', '" + anchorHref + "', '" + resultsContent + "' )" ); } } } } } catch ( ParserException pe ) { pe.printStackTrace(); } } } } public static void BidCorp() { if ( searchState.equals("ALL" ) ) { try { String line; while ((line = reader.readLine()) != null) { resp += line; } reader.close(); int vsIdx = resp.indexOf("id=\"__VIEWSTATE\""); int endIdx = resp.indexOf("=\" />"); vsIdx = resp.indexOf("id=\"__EVENTVALIDATION\""); endIdx = resp.indexOf("<table class=\"mainTable\""); String message = "__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=" + URLEncoder.encode(viewState) + "&__EVENTVALIDATION=" + URLEncoder.encode(evtValidation) + "&ctl00$ContentPlaceHolder1$txtKeywords=" + URLEncoder.encode( searchString ) + "&ctl00$ContentPlaceHolder1$rdoKeywordStatus=" + URLEncoder.encode("3") + "&ctl00$ContentPlaceHolder1$btnSubmitKeyword=" + URLEncoder.encode("Submit") + "&ctl00$ContentPlaceHolder1$txtLotNumber="; conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); conn.setRequestProperty("User-Agent","Mozilla/5.0"); writer.write(message.getBytes("UTF-8")); writer.close(); line = ""; resp = ""; while ((line = myReader.readLine()) != null) { resp += line; } myReader.close(); int startIdx = resp.indexOf("<table cellspacing=\"0\" cellpadding=\"4\""); endIdx = resp.indexOf("<div style=\"margin: 5px; "); if ( startIdx > 0 && endIdx > startIdx ) { try { htmlParser.setInputHTML( resp.substring(startIdx,endIdx) ); NodeList nList = htmlParser.parse(null); if ( nList.size() > 0 ) { NodeList trList = nList.elementAt(0).getChildren(); for ( int i=0; i<trList.size(); i++ ) { if ( trList.elementAt(i).getText().contains("bgcolor=\"White\"") || trList.elementAt(i).getText().contains("bgcolor=\"#CCCCCC\"") ) { NodeList tdList = trList.elementAt(i).getChildren(); if ( tdList.size() > 2 ) { resultsContent = resultsContent.replaceAll("\"", ""); resultsContent = resultsContent.replaceAll("\n", ""); resultsContent = resultsContent.replaceAll("\t", ""); try { stmt.executeUpdate( "INSERT INTO auction_records VALUES ( 'http://www.bidcorp.com/', '" + anchorHref + "', '" + resultsContent + "' )" ); } } } } } catch ( ParserException pe ) { pe.printStackTrace(); } } } } public static void bid4Assets() { try { if ( searchState.equals("ALL") ) { stateSearch = "all"; } else { stateSearch = searchState; } String message = "fuseaction=" + URLEncoder.encode("search") + "&type=" + URLEncoder.encode( "powerSearch" ) + "&criteria=" + URLEncoder.encode( searchString ) + "&keywordType=" + URLEncoder.encode( "allWords" ) + "&channel=" + URLEncoder.encode("all") + "&cat2=" + URLEncoder.encode("all") + "&cat3=" + URLEncoder.encode("all") + "&LocationChoice=" + URLEncoder.encode("1") + "&locatedState=" + URLEncoder.encode( stateSearch ) + "&ZIp=&ZipRadius=" + URLEncoder.encode("1") + "&assetstatus=" + URLEncoder.encode("Live") + "&DateHistory=" + URLEncoder.encode("6") + "&sort=" + URLEncoder.encode("bidCloseTime"); connection.setDoOutput( true ); connection.setRequestMethod( "POST" ); connection.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded" ); writer.write( message.getBytes("UTF-8") ); writer.close(); String line; while ((line = reader.readLine()) != null) { responseContent += line; } reader.close(); int startIdx = responseContent.indexOf( "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\">" ); int endIdx = responseContent.indexOf( "<!-- google_ad_section_end" ); if ( startIdx<0 || endIdx<0 ) return; try { // System.out.println( startIdx + " " + endIdx ); if ( startIdx > 0 && endIdx > 0 ) { htmlParser.setInputHTML( responseContent.substring( startIdx, endIdx ) ); NodeList nList = htmlParser.parse( null ); if ( nList.size() > 4 ) { NodeList trList = nList.elementAt(4).getChildren(); for ( int i=0; i<trList.size(); i++ ) { if ( !trList.elementAt(i).toPlainTextString().trim().equals("") ) { resultsContent = resultsContent.replaceAll("\"", ""); resultsContent = resultsContent.replaceAll("\n", " "); resultsContent = resultsContent.replaceAll("\t", " "); resultsContent = resultsContent.replace("\\", ""); resultsContent = resultsContent.replaceAll("'", ""); NodeList tdList = trList.elementAt(i).getChildren(); try { for ( int j=0; j<tdList.size(); j++ ) { if ( tdList.elementAt(j).getText().contains("mediumArial02") ) { NodeList aList = tdList.elementAt(j).getChildren(); for ( int k=0; k<aList.size(); k++ ) { if ( aList.elementAt(k).getText().contains("href") ) { anchorHref = "http://www.bid4assets.com/" + anchorHref.substring(0,anchorHref.length()-1); //System.out.println( "6" ); try { stmt.executeUpdate( "INSERT INTO auction_records VALUES ( 'http://www.bid4assets.com/', '" + anchorHref + "', '" + resultsContent + "' )" ); } } } } } } } } } catch ( ParserException pe ) { pe.printStackTrace(); } } public static void BankruptcySales() { if ( searchState.equals("ALL" ) ) { try { conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); conn.setRequestProperty("User-Agent","Mozilla/5.0"); os.write(msg.getBytes("UTF-8")); os.close(); String line; while ((line = lector.readLine())!= null) { resp = resp.concat(line); } lector.close(); int startIdx = resp.indexOf("<!-- InstanceBeginEditable name=\"Body\" -->"); int endIdx = resp.indexOf("CLASS=\"bottomLinks\""); try { htmlParser.setInputHTML( resp.substring(startIdx,endIdx) ); NodeList nList = htmlParser.parse(null); for ( int i=0; i<nList.size(); i++ ) { if ( nList.elementAt(i).getText().startsWith("TABLE WIDTH=\"95%\"") ) { NodeList nextChildren = nList.elementAt(i).getChildren(); for ( int j=0; j<nextChildren.size(); j++ ) { if ( nextChildren.elementAt(j).getText().equals("TR") ) { NodeList nxtChildren = nextChildren.elementAt(j).getChildren(); if ( nxtChildren.size() > 0 ) { NodeList pChildren = nxtChildren.elementAt(1).getChildren(); for ( int k=0; k<pChildren.size(); k++ ) { if ( pChildren.elementAt(k).getText().startsWith("TABLE WIDTH=\"95%\"") ) { NodeList trList = pChildren.elementAt(k).getChildren(); for ( int l=2; l<trList.size(); l++ ) { if ( !trList.elementAt(l).toPlainTextString().trim().equals("") ) { resultsContent = resultsContent.replaceAll("\t",""); resultsContent = resultsContent.replaceAll("\n",""); while ( resultsContent.contains(" ") ) { resultsContent = resultsContent.replaceAll(" ",""); } if ( hrefCandidates.length > 0 ) { anchorHref = "http://www.bankruptcysales.com/" + anchorHref; try { //System.out.println( "INSERT INTO auction_records VALUES ( 'http://www.bankruptcysales.com/', '" + anchorHref + "', '" + resultsContent + "' )" ); stmt.executeUpdate( "INSERT INTO auction_records VALUES ( 'http://www.bankruptcysales.com/', '" + anchorHref + "', '" + resultsContent + "' )" ); } } } } } } } } } } } catch ( ParserException pe ) { pe.printStackTrace(); } } } public static void PublicSurplus() { try { String stateSearch = searchState; if ( searchState.equals("ALL") ) stateSearch = ""; String message = "http://www.publicsurplus.com/sms/browse/search?posting=y&slth=&page=0&sortBy=timeLeft&keyWord=" + searchString + "&catId=-1&endHours=-1&startHours=-1&lowerPrice=0&higherPrice=0&milesLocation=-1&zipCode=®ion=" + "all%2C" + stateSearch; String line; while ((line = reader.readLine()) != null) { resp += line; } reader.close(); int startIdx = resp.indexOf("<div class=\"SepTable\">"); int endIdx = resp.indexOf("Hide Images"); if ( startIdx > 0 && endIdx > 0 ) { //System.out.println( resp.substring(startIdx,endIdx) ); try { htmlParser.setInputHTML(resp.substring(startIdx,endIdx)); NodeList nList = htmlParser.parse(null); for ( int i=0; i<nList.size(); i++ ) { if ( nList.elementAt(i).getText().equals("table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"5\" class=\"tabCurr\"") ) { NodeList tHeadList = nList.elementAt(i).getChildren(); for ( int j=4; j<tHeadList.size(); j++ ) { if ( tHeadList.elementAt(j).getText().startsWith("tr") ) { resultsContent = resultsContent.replaceAll(" ",""); resultsContent = resultsContent.replaceAll("\n",""); resultsContent = resultsContent.replaceAll("\t",""); while ( resultsContent.contains(" ") ) { resultsContent = resultsContent.replaceAll(" "," "); } //System.out.println( resultsContent ); try { stmt.executeUpdate( "INSERT INTO auction_records VALUES ( 'http://http://www.publicsurplus.com/', '" + anchorHref + "', '" + resultsContent + "' )" ); } } } } } catch ( ParserException pe ) { pe.printStackTrace(); } } } public static void GovernmentAuction() { if ( searchState.equals("ALL" ) ) { String message = "http://auctions.governmentauction.com/view-auctions/individual-lots/?key=" + searchString + "&page=1&cat=&catm=any&order=timeleft&live=yes&timed=yes®ular=yes&buynow=yes&makeoffer=yes&auctioneer=&minprice=&maxprice=&items=48"; try { String line; while ((line = reader.readLine()) != null) { resp += line; } reader.close(); int startIdx = resp.indexOf("<div id=\"lac"); int endIdx = resp.indexOf("<div id=\"footer\">"); if ( startIdx > 0 && endIdx > startIdx ) { try { prse.setInputHTML( resp.substring(startIdx,endIdx) ); NodeList nList = prse.parse(null); for ( int i=0; i<nList.size(); i++ ) { if ( nList.elementAt(i).getText().contains("id=\"lac") ) { NodeList divList = nList.elementAt(i).getChildren(); for ( int j=0; j<divList.size(); j++ ) { if ( divList.elementAt(j).getText().equals("div class=\"name\"") ) { resultsContent = resultsContent.replaceAll("\n",""); resultsContent = resultsContent.replaceAll("\t",""); while ( resultsContent.contains(" ") ) { resultsContent = resultsContent.replaceAll(" "," "); } //System.out.println( resultsContent ); anchorHref = "http://auctions.governmentauction.com" + anchorHref; try { stmt.executeUpdate( "INSERT INTO auction_records VALUES ( 'http://auctions.governmentauction.com', '" + anchorHref + "', '" + resultsContent + "' )" ); } } } } } catch ( ParserException pe ) { pe.printStackTrace(); } } } } public static void HomeSteps() { if ( searchState.equals("ALL" ) ) { return; } String msg = "City=&County=&State=" + URLEncoder.encode(searchState) + "&Zip=&PriceRangeLow=" + URLEncoder.encode("*") + "&PriceRangeHigh=" + URLEncoder.encode("*") + "&TotalRooms=" + URLEncoder.encode("*") + "&NumberBedrooms=" + URLEncoder.encode("*") + "&NumberBathrooms=" + URLEncoder.encode("*") + "&B1=Find Homes&IPP=50"; try { conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); conn.setRequestProperty("User-Agent","Mozilla/5.0"); os.write(msg.getBytes("UTF-8")); os.close(); String line; while ((line = myReader.readLine())!= null) { resp = resp.concat(line); } myReader.close(); int startIdx = resp.indexOf("<table cellpadding=1 cellspacing=1 class=tblHomesteps>"); int endIdx = resp.indexOf("Freddie Mac takes"); try { prsr.setInputHTML(resp.substring(startIdx,endIdx)); NodeList nList = prsr.parse(null); for ( int i=0; i<nList.size(); i++ ) { if ( nList.elementAt(i).getText().equals("table cellpadding=1 cellspacing=1 class=tblHomesteps") ) { NodeList trList = nList.elementAt(i).getChildren(); for ( int j=2; j<trList.size(); j++ ) { if ( trList.elementAt(j).getText().equals("tr") ) { resultsContent = resultsContent.replaceAll("\n",""); resultsContent = resultsContent.replaceAll("\t",""); while ( resultsContent.contains(" ") ) { resultsContent = resultsContent.replaceAll(" "," "); } try { stmt.executeUpdate( "INSERT INTO auction_records VALUES ( 'http://www.homesteps.com/featuresearch.html', '" + anchorHref + "', '" + resultsContent + "' )" ); } } } } } catch ( ParserException pe ) { pe.printStackTrace(); } } public static void HomePath() { if ( searchState.equals("ALL" ) ) { return; } String message = "http://www.homepath.com/search.html?st=" + searchState + "&cno=000&ci=&zip=&src_ref=&mlsid=&pi=&pa=&bdi=&bhi=&x=26&y=11&ms=&xs="; try { String line; while ((line = reader.readLine()) != null) { resp += line; } reader.close(); int startIdx = resp.indexOf("<table class=\"multipleLinesSearchResults\""); int endIdx = resp.indexOf("Get FREE HomePath"); if ( startIdx > 0 && endIdx > 0 ) { try { htmlParser.setInputHTML(resp.substring(startIdx,endIdx)); NodeList nList = htmlParser.parse(null); for ( int i=0; i<nList.size(); i++ ) { if ( nList.elementAt(i).getText().equals("table class=\"multipleLinesSearchResults\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\"") ) { NodeList trList = nList.elementAt(i).getChildren(); for ( int j=0; j<trList.size(); j++ ) { if ( trList.elementAt(j).getText().startsWith("tr class") ) { resultsContent = resultsContent.replaceAll("\n",""); resultsContent = resultsContent.replaceAll("\t",""); resultsContent = resultsContent.replaceAll(" ",""); resultsContent = resultsContent.replaceAll("SaveMap",""); while ( resultsContent.contains(" ") ) { resultsContent = resultsContent.replaceAll(" "," "); } //System.out.println( resultsContent ); anchorHref = anchorHref; anchorHref = "http://www.homepath.com" + anchorHref; if ( !resultsContent.equals("") ) { try { stmt.executeUpdate( "INSERT INTO auction_records VALUES ( 'http://www.homepath.com/', '" + anchorHref + "', '" + resultsContent + "' )" ); } } } } } } catch ( ParserException pe ) { pe.printStackTrace(); } } } public static void HomeSalesGov() { if ( searchState.equals("ALL" ) ) { return; } String msg = "selectedCities=" + URLEncoder.encode("ALL") + "&selBedrooms=&selBaths=&pageAction=" + URLEncoder.encode("Search for Properties") + "&stateName=" + URLEncoder.encode( stateMap.get(searchState) ) + "&state=" + URLEncoder.encode(searchState) + "&propertyType=" + URLEncoder.encode("RESIDENTIAL"); try { conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); conn.setRequestProperty("User-Agent","Mozilla/5.0"); os.write(msg.getBytes("UTF-8")); os.close(); String line; while ((line = myReader.readLine())!= null) { resp = resp.concat(line); } myReader.close(); int startIdx = resp.indexOf("<table width=\"80%\" align=\"center\" border=\"0\" rules=\"none\">"); int endIdx = resp.indexOf(" Total Result Pages:"); if ( startIdx > 0 && endIdx > startIdx ) { try { prs.setInputHTML(resp.substring(startIdx,endIdx)); NodeList nList = prs.parse(null); for ( int i=0; i<nList.size(); i++ ) { if ( nList.elementAt(i).getText().startsWith("table width=\"80%\"") ) { NodeList trList = nList.elementAt(i).getChildren(); for ( int j=0; j<trList.size(); j++ ) { if ( trList.elementAt(j).getText().equals("tr") ) { resultsContent = resultsContent.replaceAll(" ",""); resultsContent = resultsContent.replaceAll("\n",""); resultsContent = resultsContent.replaceAll("\t",""); while ( resultsContent.contains(" ") ) { resultsContent = resultsContent.replaceAll(" "," "); } if ( pieces.length > 1 ) { if ( piecesII.length > 0 ) { anchorHref = anchorHref; try { stmt.executeUpdate( "INSERT INTO auction_records VALUES ( 'http://www.homepath.com/', '" + anchorHref + "', '" + resultsContent + "' )" ); } } } } } } } catch ( ParserException pe ) { pe.printStackTrace(); } } } public static void HudHomeStore() { if ( searchState.equals("ALL" ) ) { return; } String message = "https://hudhomestore.secureportalk.net/HUD/PropertySearchResult.aspx?PageId=1&zipCode=&city=&county=&sState="+searchState+"&fromPrice=0&toPrice=0&caseNumber=&bed=0&bath=0&street=&buyerType=0&specialProgram=&Status=0&OrderbyName=SCASENUMBER&OrderbyValue=ASC&sPageSize=50"; try { String line; while ((line = reader.readLine()) != null) { resp += line; } reader.close(); int startIdx = resp.indexOf("<tr class=\"FormTablerow\""); int endIdx = resp.indexOf("<!-- ============= Data List"); try { p.setInputHTML(resp.substring(startIdx,endIdx)); NodeList nList = p.parse(null); for ( int i=0; i<nList.size(); i++ ) { if ( nList.elementAt(i).getText().startsWith("tr class=\"FormTablerow") ) { resultsContent = resultsContent.replaceAll(" ",""); resultsContent = resultsContent.replaceAll("\n",""); resultsContent = resultsContent.replaceAll("\t",""); resultsContent = resultsContent.replaceAll("Exclusive",""); resultsContent = resultsContent.replaceAll("View",""); resultsContent = resultsContent.replaceAll("Street",""); resultsContent = resultsContent.replaceAll("Map it",""); resultsContent = resultsContent.replaceAll("Email",""); resultsContent = resultsContent.replaceAll("Info",""); resultsContent = resultsContent.replaceAll("Extended",""); resultsContent = resultsContent.replaceAll("Lottery",""); while ( resultsContent.contains(" ") ) { resultsContent = resultsContent.replaceAll(" "," "); } //System.out.println( resultsContent ); NodeList tdList = nList.elementAt(i).getChildren(); for ( int j=0; j<tdList.size(); j++ ) { if ( tdList.elementAt(j).getText().startsWith("td align=\"center\" valign=\"middle\"") ) { NodeList aList = tdList.elementAt(j).getChildren(); for ( int k=0; k<aList.size(); k++ ) { if ( aList.elementAt(k).getText().startsWith("a href=\"#;\"") ) { String[] pieces = aList.elementAt(k).getText().split(Pattern.quote("getGoogleTranslationstring('")); if ( pieces.length > 0 ) { if ( piecesII.length > 0 ) { try { System.out.println( "INSERT INTO auction_records VALUES ( 'http://www.hudhomestore.com/', '" + anchorHref + "', '" + resultsContent + "' )" ); stmt.executeUpdate( "INSERT INTO auction_records VALUES ( 'http://www.hudhomestore.com/', '" + anchorHref + "', '" + resultsContent + "' )" ); } } } } } } } } } catch ( ParserException pe ) { pe.printStackTrace(); } } public static void GSAGov() { if ( searchState.equals("ALL" ) ) { return; } String message = "https://extportal.pbs.gsa.gov/ResourceCenter/PRHomePage/searchProperty.do?state=5&statename=" + stateMap.get(searchState).toUpperCase() + "&propType=&propTypeName=ALL&searchType=S"; try { String line; while ((line = reader.readLine()) != null) { resp += line; } reader.close(); int startIdx = resp.indexOf("<div class=\"cmSectionText\">"); int endIdx = resp.indexOf("<!-- div cmSectionText -->"); if ( startIdx > 0 && endIdx > startIdx ) { try { p.setInputHTML( resp.substring(startIdx,endIdx) ); NodeList nList = p.parse(null); for ( int i=0; i<nList.size(); i++ ) { if ( nList.elementAt(i).getText().startsWith("div class=\"cmSectionText\"") ) { NodeList divChildren = nList.elementAt(i).getChildren(); for ( int j=0; j<divChildren.size(); j++ ) { if ( divChildren.elementAt(j).getText().contains("D1D1D1") ) { resultsContent = resultsContent.replaceAll("Click here for more information",""); resultsContent = resultsContent.replaceAll(" ",""); resultsContent = resultsContent.replaceAll("\n",""); resultsContent = resultsContent.replaceAll("\t",""); resultsContent = resultsContent.replaceAll("\"",""); while ( resultsContent.contains(" ") ) { resultsContent = resultsContent.replaceAll(" "," "); } //System.out.println( resultsContent ); //System.out.println( htm ); int hrefIdx = htm.indexOf("loadProperty.do"); if ( hrefIdx > 0 ) { if ( pieces.length > 0 ) { anchorHref = "https://extportal.pbs.gsa.gov/ResourceCenter/PRHomePage/" + anchorHref; try { //System.out.println( "INSERT INTO auction_records VALUES ( 'https://propertydisposal.gsa.gov/', '" + anchorHref + "', '" + resultsContent + "' )" ); stmt.executeUpdate( "INSERT INTO auction_records VALUES ( 'https://propertydisposal.gsa.gov/', '" + anchorHref + "', '" + resultsContent + "' )" ); } } } } } } } catch ( ParserException pe ) { pe.printStackTrace(); } } } public static void GovSales() { try { String line; while ((line = reader.readLine()) != null) { resp += line; } reader.close(); int scParamIdx = resp.indexOf("name=scParam VALUE=\""); if ( scParamIdx > 0 ) { scParam = resp.substring(scParamIdx, scParamIdx+80); if ( pieces.length > 1 ) { if ( piecesII.length > 1 ) { scParam = piecesII[0].trim(); } } } int webPcmIdx = resp.indexOf("WEBPCMTRANSID"); if ( webPcmIdx > 0 ) { webPcm = resp.substring(webPcmIdx, webPcmIdx+40); if ( pieces.length > 1 ) { if ( piecesII.length > 1 ) { webPcm = piecesII[1].trim(); } } } String msg2 = "scParam=" + URLEncoder.encode( scParam ) + "&scCurTabCat=" + URLEncoder.encode("010000000000") + "&scSelTabCat=" + URLEncoder.encode("010000000000") + "&scSelLink=" + URLEncoder.encode("GS") + "&scGSName=" + URLEncoder.encode( searchString.toUpperCase() ) + "&scGSOptn=" + URLEncoder.encode("1") + "&scSelState=&scSelBCCat=&scSelRow=&scSelCatList=&scSeeAllCat=&WEBPCMTRANSID=" + URLEncoder.encode( webPcm ); conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); conn.setRequestProperty("User-Agent","Mozilla/5.0"); os.write(msg2.getBytes("UTF-8")); os.close(); String rayo; while ((rayo = lecteur.readLine())!= null) { resp2 += rayo; } lecteur.close(); scParam = ""; scParamIdx = resp2.indexOf("name=scParam VALUE=\""); if ( scParamIdx > 0 ) { scParam = resp2.substring(scParamIdx, scParamIdx+80); if ( pieces.length > 1 ) { if ( piecesII.length > 1 ) { scParam = piecesII[0].trim(); } } } int scSL1Idx = resp2.indexOf("name=scStoreLocal1"); if ( scSL1Idx > 0 ) { scStoreLocal1 = resp2.substring(scSL1Idx, scSL1Idx+160); if ( pieces.length > 1 ) { if ( piecesII.length > 1 ) { scStoreLocal1 = piecesII[0].trim(); } } } int scSL2Idx = resp2.indexOf("name=scStoreLocal2"); if ( scSL1Idx > 0 ) { scStoreLocal2 = resp2.substring(scSL2Idx, scSL2Idx+160); if ( pieces.length > 1 ) { if ( piecesII.length > 1 ) { scStoreLocal2 = piecesII[0]; } } } int scSL3Idx = resp2.indexOf("name=scStoreLocal3"); if ( scSL3Idx > 0 ) { scStoreLocal3 = resp2.substring(scSL3Idx, scSL3Idx+160); if ( pieces.length > 1 ) { if ( piecesII.length > 1 ) { scStoreLocal3 = piecesII[0]; } } } int scSL5Idx = resp2.indexOf("name=scStoreLocal5"); if ( scSL5Idx > 0 ) { scStoreLocal5 = resp2.substring(scSL5Idx, scSL5Idx+160); if ( pieces.length > 1 ) { if ( piecesII.length > 1 ) { scStoreLocal5 = piecesII[0]; } } } webPcm = ""; webPcmIdx = resp2.indexOf("WEBPCMTRANSID"); if ( webPcmIdx > 0 ) { webPcm = resp2.substring(webPcmIdx, webPcmIdx+40); if ( pieces.length > 1 ) { if ( piecesII.length > 1 ) { webPcm = piecesII[1].trim(); } } } String msg3 = "scParam=" + URLEncoder.encode( scParam ) + "&scStoreLocal1=" + URLEncoder.encode( scStoreLocal1 ) + "&scStoreLocal2=" + URLEncoder.encode( scStoreLocal2 ) + "&scStoreLocal3=" + URLEncoder.encode( scStoreLocal3 ) + "&scStoreLocal4=&scStoreLocal5=" + URLEncoder.encode( scStoreLocal5 ) + "&scStoreLocal6=&scStoreLocal7=&scStoreLocal8=&scStoreLocal9=&scStoreLocal10=&scStoreLocal11=&scStoreLocal12=&scCurTabCat=&scSelTabCat=&scSelLink=&scGSName=&scGSOptn=" + URLEncoder.encode("1") + "&scSelState=&scSelRow=" + URLEncoder.encode("2G1WB58K381263163") + "&scSortOrder=&scPageNo=" + URLEncoder.encode("1") + "&WEBPCMTRANSID=" + URLEncoder.encode("0690484,2970121"); //System.out.println( msg3 ); int startIdx = resp2.indexOf("var tab="); int endIdx = resp2.indexOf("bldTr();"); String dataBlock = resp2.substring(startIdx,endIdx).replaceAll(Pattern.quote("["),"").replaceAll(Pattern.quote("];"),""); dataBlock = dataBlock.replaceAll("var tab=\"",""); dataBlock = dataBlock.replaceAll(" "," "); //System.out.println( dataBlock ); ArrayList<String> resultsContentStrings = new ArrayList<String>(); ArrayList<String> urlIdList = new ArrayList<String>(); for ( int i=0; i<dataBlockPieces.length; i+=12 ) { for ( int j=0; j<12; j++ ) { content += dataBlockPieces[i+j] + " "; } resultsContentStrings.add( content ); urlIdList.add( dataBlockPieces[i+1] ); } ArrayList<String> msgs = new ArrayList<String>(); msgs.add( "scParam=" + URLEncoder.encode( scParam ) + "&scStoreLocal1=" + URLEncoder.encode( scStoreLocal1 ) + "&scStoreLocal2=" + URLEncoder.encode( scStoreLocal2 ) + "&scStoreLocal3=" + URLEncoder.encode( scStoreLocal3 ) + "&scStoreLocal4=&scStoreLocal5=" + URLEncoder.encode( scStoreLocal5 ) + "&scStoreLocal6=&scStoreLocal7=&scStoreLocal8=&scStoreLocal9=&scStoreLocal10=&scStoreLocal11=&scStoreLocal12=&scCurTabCat=&scSelTabCat=&scSelLink=&scGSName=&scGSOptn=" + URLEncoder.encode("1") + "&scSelState=&scSelRow=" + URLEncoder.encode( urlId ) + "&scSortOrder=&scPageNo=" + URLEncoder.encode("1") + "&WEBPCMTRANSID=" + URLEncoder.encode("0690484,2970121") ); } ArrayList<String> urlList = new ArrayList<String>(); urlList.add( "javascript:jQuery.post( "http://www.govsales.gov/fassys/fassrchlist/", "" + msg1 + "" )" ); } for ( int i=0; i<resultsContentStrings.size()-1; i++ ) { try { stmt.executeUpdate( "INSERT INTO auction_records VALUES ( 'http://www.govsales.gov/', '" + urlList.get(i) + "', '" + resultsContentStrings.get(i) + "' )" ); } } public static void LonestarOnline() { String msg = "search_type=title_search&search_name=Title+%26+Description+Search&search_text=" + searchString + "&phrase_match=any&category=-1&search_span=title&search_limit=active&order_by=title&sort_order=ASC"; try { String line; while ((line = reader.readLine()) != null) { resp += line; } reader.close(); int startIdx = resp.indexOf("<table border=0 cellspacing=0 cellpadding=2 noshade width=780>"); int endIdx = resp.indexOf("<form name=\"blah\""); if ( startIdx > 0 && endIdx > startIdx ) { //System.out.println( startIdx + " " + endIdx ); try { //System.out.println( resp.substring( startIdx, endIdx ) ); psr.setInputHTML( resp.substring(startIdx,endIdx) ); NodeList nList = psr.parse(null); for ( int i=0; i<nList.size(); i++ ) { if ( nList.elementAt(i).getText().equals("table border=0 cellspacing=0 cellpadding=2 noshade width=780") ) { NodeList trList = nList.elementAt(i).getChildren(); for ( int j=0; j<trList.size(); j++ ) { if ( trList.elementAt(j).getText().startsWith("tr") ) { resultsContent = resultsContent.replaceAll(" ",""); resultsContent = resultsContent.replaceAll("\n",""); resultsContent = resultsContent.replaceAll("\t",""); resultsContent = resultsContent.replaceAll("\"",""); resultsContent = resultsContent.replaceAll("'",""); while ( resultsContent.contains(" ") ) { resultsContent = resultsContent.replaceAll(" "," "); } NodeList tdList = trList.elementAt(j).getChildren(); for ( int k=0; k<tdList.size(); k++ ) { if ( tdList.elementAt(k).getText().equals("td width=\"496\"") ) { if ( pieces.length > 1 ) { try { stmt.executeUpdate( "INSERT INTO auction_records VALUES ( 'http://www.lonestaronline.com', '" + anchorHref + "', '" + resultsContent + "' )" ); } } } } } } } } catch ( ParserException pe ) { pe.printStackTrace(); } } } public static void GovDeals() { if ( searchState.equals("ALL") ) { msg = "fa=Main.AdvSearchResults&timing1=&mystate=&myseller=0&myselectbox=00&desc=" + searchString + "&inv_nbr="; } else { msg = "fa=Main.AdvSearchResults&timing1=&mystate=" + searchState + "&myseller=0&myselectbox=00&desc=" + searchString + "&inv_nbr="; } try { String line; while ((line = reader.readLine()) != null) { resp += line; } reader.close(); int startIdx = resp.indexOf("<tr bgcolor=\"#CCCCCC\">"); int endIdx = resp.indexOf("<td colspan=\"9\" style=\"border-bottom:none\" scope=\"row\">"); if ( startIdx > 0 && endIdx > startIdx ) { // System.out.println( startIdx + " " + endIdx ); try { prse.setInputHTML( resp.substring( startIdx, endIdx ) ); NodeList nList = prse.parse(null); for ( int i=0; i<nList.size(); i++ ) { if ( nList.elementAt(i).getText().startsWith("tr valign=\"top\"") ) { resultsContent = resultsContent.replaceAll(" ",""); resultsContent = resultsContent.replaceAll("\n",""); resultsContent = resultsContent.replaceAll("\t",""); resultsContent = resultsContent.replaceAll("\"",""); resultsContent = resultsContent.replaceAll("'",""); resultsContent = resultsContent.replaceAll("View by same:CategoryLocationMake/BrandModelProximity-------------Terms & ConditionsView this Item",""); while ( resultsContent.contains(" ") ) { resultsContent = resultsContent.replaceAll(" "," "); } resultsContent = resultsContent.replaceAll("0Bids","0 Bids"); //System.out.println( resultsContent ); NodeList tdList = nList.elementAt(i).getChildren(); for ( int j=0; j<tdList.size(); j++ ) { if ( tdList.elementAt(j).getText().equals("td valign=\"top\" nowrap=\"nowrap\"") ) { if ( pieces.length > 1 ) { try { stmt.executeUpdate( "INSERT INTO auction_records VALUES ( 'http://www.govdeals.com/', '" + anchorHref + "', '" + resultsContent + "' )" ); } } } } } } catch ( ParserException pe ) { pe.printStackTrace(); } } } public static void IllinoisIbid() { String msg = "search=1&catid=&SearchStr=" + searchString + "&AllAnyExact=all&Region1=&Region2=&Region3=&Region4=&customs_criteria=1&cfs_txt_EqNum=&cfs_txt_VIN=&cfs_int_min_Odometer=&cfs_int_max_Odometer=&cfs_txt_make=&cfs_txt_model=&cfs_txt_modelyear=&PriceFrom=&PriceTo=&StartFrom=&StartTo=&EndFrom=&EndTo=&ExcludeStr=&OrderBy=end_asc&MaxResults=50&sbmtAdvSearch=Go#results"; try { String line; while ((line = lecteur.readLine()) != null) { resp += line; } lecteur.close(); int startIdx = resp.indexOf( "<div id=\"SearchResults\">"); int endIdx = resp.indexOf( "<div id=\"PageLinksS\">" ); //System.out.println( startIdx + " " + endIdx ); if ( startIdx > 0 && endIdx > startIdx ) { try { prs.setInputHTML( resp.substring(startIdx,endIdx) ); NodeList nList = prs.parse(null); for ( int i=0; i<nList.size(); i++ ) { if ( nList.elementAt(i).getText().equals("div id=\"SearchResults\"") ) { NodeList tblList = nList.elementAt(i).getChildren(); for ( int j=0; j<tblList.size(); j++ ) { if ( tblList.elementAt(j).getText().equals("table cellpadding=\"2\" cellspacing=\"1\"") ) { NodeList trList = tblList.elementAt(j).getChildren(); for ( int k=0; k<trList.size(); k++ ) { if ( trList.elementAt(k).getText().startsWith("tr class=\"Color") ) { resultsContent = resultsContent.replaceAll(" ",""); resultsContent = resultsContent.replaceAll("\n",""); resultsContent = resultsContent.replaceAll("\t",""); resultsContent = resultsConte
You need to login to post a comment.
