Note that there are some explanatory texts on larger screens.

plurals
  1. POJava URLConnection Issues with Integers
    text
    copied!<p>I've been trying to get information from a webpage, specifically this site: <a href="http://www.ncbi.nlm.nih.gov/pubmed?term=%22pulmonary%20disease%2C%20chronic%20obstructive%22%5BMesh%5D" rel="nofollow">http://www.ncbi.nlm.nih.gov/pubmed?term=%22pulmonary%20disease%2C%20chronic%20obstructive%22%5BMesh%5D</a> (among other similar ones). I'm using the URL and URLConnection packages to do so. I'm trying to get a certain number from the webpage - on this page, I want the total number of articles (16428).</p> <p>It says this near the top of the page: "Results: 1 to 20 of 16428" and when I look at the page source manually I can find this. However, when I try to use the java connection to obtain this number from the page source, for some reason the number it gets is "863399" instead of "16428". </p> <p>Code:</p> <pre><code> URL connection = new URL("http://www.ncbi.nlm.nih.gov/pubmed?term=%22pulmonary%20disease%2C%20chronic%20obstructive%22%5BMesh%5D"); URLConnection yc = connection.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream())); String html = ""; String inputLine; while ((inputLine = in.readLine()) != null) html += inputLine; in.close(); int startMarker = html.indexOf("ncbi_resultcount"); int endMarker = html.indexOf("ncbi_op"); System.out.println(html.substring(startMarker, endMarker)); </code></pre> <p>When I run this code, I get: </p> <blockquote> <p>ncbi_resultcount" content="863399" /></p> </blockquote> <p>rather than: </p> <blockquote> <p>ncbi_resultcount" content="16428" /> </p> </blockquote> <p>Does anyone know why this is / how I can fix it?</p> <p>Thanks!</p>
 

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