如何从 url 中提取文本?在我的代码中,它正在提取该网址的源代码......
DefaultHttpClient client = null;
client = new DefaultHttpClient();
client.getCredentialsProvider().setCredentials(
new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM),
new UsernamePasswordCredentials("test", "test"));
client.getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);
HttpGet request = new HttpGet("http://somehost.com");
HttpResponse response = client.execute(request);
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
Tika t = new Tika();
Metadata md = new Metadata();
Reader r = t.parse(content, md);
System.out.println(md);
System.out.println("Yes1: " +md.get("keywords"));
System.out.println("Yes2: " +md.get("title"));
System.out.println("Yes3: " +md.get("authors"));
//This gives the source code of that url not the actual content...
String ss= t.parseToString(content);
System.out.println("Yes4: " +ss);
有什么建议么??