Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to optimize this ugly code?
    primarykey
    data
    text
    <p>I make the other day a question <a href="https://stackoverflow.com/questions/3368618/how-to-find-urls-in-html-using-java">here</a>, but finally I decided to do it myself for questions of time, now I have a little more time to fix it :D I liked jSoup, but I'm kind of from old school, and preffer doing it my self (thanks to @Bakkal anyway).</p> <p>I manage to made this code, it works fine for now, but if a webpage is not well contructed it will break the code, for example if it doesn't start with http the code is not going to find it, and if the url is not ending with one of the things that I put in the while it's going to return a really ugly addres.. for example</p> <blockquote> <p><a href="http://www.google.com/" rel="nofollow noreferrer">http://www.google.com/</a> hey dude how are you? great, eating at jack's</p> </blockquote> <p>My result would be:</p> <blockquote> <p><a href="http://www.google.com/" rel="nofollow noreferrer">http://www.google.com/</a> hey dude how are you? great, eating at jack</p> </blockquote> <p>I'm open to suggestions, any of them, I will resume my questions and after that I will post the code</p> <ol> <li>The code breaks if I don't have the exact ending</li> <li>If I put the space " " as a break I'm going to loose all the pages that have space in the address</li> <li>I would like to capture all addresses not only the ones starting with http, for example www.google.com is a valida address and so is contacts.google.com</li> </ol> <p>Thanks for everything :D</p> <pre><code>File txtUrlSpecialFile = new File("pepe.txt"); FileWriter txtUrlSpecial; txtUrlSpecial = new FileWriter(txtUrlSpecialFile); txtUrlSpecial.write(profundidad-1); for(int j=0;j&lt;bigString.length()-5;j++){ //I put 5 but I can put more if(bigString.substring(j, j+4).equals("http")){ while(bigString.charAt(j)!='"' &amp;&amp; bigString.charAt(j)!='&lt;'&amp;&amp; bigString.substring(j, j)!="'"){ txtUrlSpecial.write(bigString.charAt(j)); j++; } txtUrlSpecial.write(SingletonFunction.getNewLine()); } } txtUrlSpecial.close(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload