Помогите разобраться с прогой HttpClient - вопрос №2264429

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.htmlcleaner.HtmlCleaner; import org.htmlcleaner.TagNode; import org.htmlcleaner.XPatherException; public class Cl { private static final String Url = «111»; public static void main(String[] args) throws IOException, XPatherException { HttpClient httpClient = HttpClientBuilder.create().build(); //Создаем объект класса HttpGet httpGet = new HttpGet(Url);// загружаем HttpResponse response = httpClient.execute(httpGet); // получаем страницу System.out.println(«Response Code: „ + response.getStatusLine().getStatusCode()); BufferedReader rd = new BufferedReader( new InputStreamReader(response.getEntity().getContent())); StringBuffer result = new StringBuffer(); String line = “»; while ((line = rd.readLine()) != null) { result.append(line); } HttpEntity entity = response.getEntity(); // входящие данные if (entity != null) { InputStream instream = entity.getContent(); try { HtmlCleaner cleaner = new HtmlCleaner(); TagNode html = cleaner.clean(instream); Object[] tags = html.evaluateXPath("//div[@class='ns_object_title']/a"); ArrayList al = new ArrayList(); for (Object tag: tags) { TagNode aTag = (TagNode) tag; String Href = aTag.getAttributeByName(«href»).trim(); al.add(Href.trim()); System.out.println(al.toString()+"\n\r"); } } catch (RuntimeException ex) { httpGet.abort(); throw ex; } finally { instream.close(); } } } }
28.12.16
0 ответов
Ответов пока нет
Посмотреть всех экспертов из раздела Технологии > Java/J2EE
Пользуйтесь нашим приложением Доступно на Google Play Загрузите в App Store