Results 1 to 3 of 3
Thread: problem with InputStreamReader
- 12-12-2010, 03:59 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 10
- Rep Power
- 0
problem with InputStreamReader
Hello all!
I have a function search(String target) that return me the correct link that I need.
I use this link for this function
But get error on:Java Code:public static String htmlContentParser(URL address) throws MalformedURLException, IOException{ String sourceLine; String content = ""; // The URL address of the page to open. // Open the address and create a BufferedReader with the source code. InputStreamReader pageInput = new InputStreamReader(address.openStream()); BufferedReader source = new BufferedReader(pageInput);
InputStreamReader pageInput = new InputStreamReader(address.openStream());
The errors are:
Exception in thread "main" java.io.FileNotFoundException: http://www.gsmarena.com/samsung galaxy-3294.php
at sun.net.http://www.protocol.http.HttpURLConn...tion.java:1311)
at java.net.URL.openStream(URL.java:1010)
at datamining.html.extratorNodes.htmlContentParser(ex tratorNodes.java:116)
at datamining.html.extratorNodes.<init>(extratorNodes .java:41)
at datamining.html.getTraningDate.main(getTraningDate .java:34)
when I dont use search(target) and sent to htmlContentParser the link manually it's all work fine.
Why is that?
the code of search is:
thanks a lotJava Code:public String search(String target) { //Convert the target to lowerCase target=target.toLowerCase(); if (target.length()==0)return "model is empty"; target = target.trim( ); //QueryString query = new QueryString("search", target); try {//Open the URL for reading URL address = new URL("http://www.gsmarena.com/results.php3?sQuickSearch=yes&sName=" + target); System.out.println("the links to search is: " +address); //Get links from the page,links-all the links from the correct page HTMLLinkExtrator links = new HTMLLinkExtrator(); ArrayList correctLinks = new ArrayList(); links.LinkExtrator(address.toString()); InputStream in = new BufferedInputStream(address.openStream()); // Chain the InputStream to a Reader InputStreamReader theHTML = new InputStreamReader(in); //System.out.println(StreamToString(theHTML)); //Find in the links the target word like (iphone 4)-->(iphone_4) correctLinks=links.findCorrectLinks(target.replaceAll(" ","_"),links.listLinks); //If the model(target) not found the print empty if (correctLinks.isEmpty()) System.out.println("the correctLinks is empty ");else { //ModelId is the id of the model in the web http://www.gsmarena.com/ String modelId=links.link(correctLinks.get(0).toString(),"-",".php"); if ((modelId.length()!=0)){ //Creating the link for the model URL corectModel = new URL("http://www.gsmarena.com/"+target+modelId+".php"); //Return the correct link of the target model System.out.println("the correct link of model is: "+correctLinks.get(0)); theHTML.close(); in.close(); return corectModel.toString(); }else System.out.println("not found");} //System.out.println("the first link: "+correctLinks.get(0)); } catch (IOException e) { System.err.println(e); } return "not found"; }
- 12-12-2010, 04:22 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
i think the problem is the space between samsung and galaxy !
replace it with '+' sign, or use URLEncoder.encode.
works fine.Java Code:URL address = new URL("http://www.gsmarena.com/"+URLEncoder.encode("samsung galaxy-3294.php", "UTF-8"));
- 12-12-2010, 04:44 PM #3
Member
- Join Date
- Mar 2010
- Posts
- 10
- Rep Power
- 0
Similar Threads
-
Client cannot retrieve all strings from the InputStreamReader through a loop
By yadav in forum NetworkingReplies: 0Last Post: 05-19-2010, 05:38 PM -
BufferedReader/InputStreamReader - NON-TECHNICAL
By Abder-Rahman in forum New To JavaReplies: 4Last Post: 09-27-2009, 10:49 PM -
Problem with ÅÄÖ in InputStreamReader, pls help
By hyperkossan in forum New To JavaReplies: 0Last Post: 12-10-2008, 08:50 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks