小编典典

这是我要怎么做:

StringBuffer text = new StringBuffer();

HttpURLConnection conn = null;

InputStreamReader in = null;

BufferedReader buff = null;

try {

URL page = new URL(

"http://example.com/");

// URLEncoder.encode(someparameter); use when passing params that may contain symbols or spaces use URLEncoder to encode it and conver space to %20...etc other wise you will get a 404

conn = (HttpURLConnection) page.openConnection();

conn.connect();

/* use this if you need to

int responseCode = conn.getResponseCode();

if (responseCode == 401 || responseCode == 403) {

// Authorization Error

Log.e(tag, "Authorization Error");

throw new Exception("Authorization Error");

}

if (responseCode >= 500 && responseCode <= 504) {

// Server Error

Log.e(tag, "Internal Server Error");

throw new Exception("Internal Server Error");

}*/

in = new InputStreamReader((InputStream) conn.getContent());

buff = new BufferedReader(in);

String line = "anything";

while (line != null) {

line = buff.readLine();

String found = interpretHtml(line);

if(null != found)

return found; // comment the previous 2 lines and this one if u need to load the whole html document.

text.append(line + "\n");

}

} catch (Exception e) {

Log.e(Standards.tag,

"Exception while getting html from website, exception: "

+ e.toString() + ", cause: " + e.getCause()

+ ", message: " + e.getMessage());

} finally {

if (null != buff) {

try {

buff.close();

} catch (IOException e1) {

}

buff = null;

}

if (null != in) {

try {

in.close();

} catch (IOException e1) {

}

in = null;

}

if (null != conn) {

conn.disconnect();

conn = null;

}

}

if (text.toString().length() > 0) {

return interpretHtml(text.toString()); // use this if you don't need to load the whole page.

} else return null;

}

private String interpretHtml(String s){

if(s.startsWidth("

return s.substring(22, s.length() - 10);

}

return null;

}

2020-10-15

Android在Java获取组件,在Java中解析HTML以获取Android应用相关推荐

  1. 【JSON】java获取json数组格式中的值

    [JSON]java获取json数组格式中的值 前情回顾 java获取json数组格式中的值 参考资料 前情回顾 写项目的中间需要解决下面这样问题: 1.从kafka中读取数据,读取出来的是json格 ...

  2. java获取系统信息:java的信息、操作系统的信息、用户的信息、虚拟机的信息、系统设置的信息。

    全栈工程师开发手册 (作者:栾鹏) java教程全解 java获取系统信息:java的信息.操作系统的信息.用户的信息.虚拟机的信息.系统设置的信息. package com.lp.app.windo ...

  3. Java获取项目当前请求的全部URL,Java获取Referer,Java获取完整链接地址URL

    Java获取项目当前请求的全部URL,Java获取Referer,Java获取完整链接地址URL >>>>>>>>>>>>> ...

  4. java如何从地址串中解析提取省市区(完美匹配中国所有地址)

    https://download.csdn.net/download/cncjh/12249234 java如何从地址串中解析提取省市区(完美匹配中国所有地址) / 张生荣 java从地址串中解析提取 ...

  5. 【Android NDK 开发】NDK 交叉编译 ( Ubuntu 中交叉编译动态库 | Android Studio 中配置使用第三方动态库 )

    文章目录 I . 动态库 与 静态库 II . 编译动态库 III. Android Studio 使用第三方动态库 IV . Android Studio 关键代码 V . 博客资源 I . 动态库 ...

  6. java获取response数据_Java中实现Http请求并获取响应数据

    前言 在演示的功能代码中使用的请求http地址为:http://timor.tech/api/holiday/year/ 接口说明:获取指定年份或年月份的所有节假日信息.默认返回当前年份的所有信息. ...

  7. java 获取键盘输入法_Java中接收键盘输入的三种方法

    import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import ...

  8. java获取json数组格式中的值

    第一种方法: String str = "{'array':[{'id':5,'name':'张三'},{'id':6,'name':'李四'}]}";JSONArray json ...

  9. java 获取组件大小_java - 如何初始化取决于组件大小的图像抓取? - 堆栈内存溢出...

    如果我正确理解问题,那么您的方法会有些落后. 与其让ImageNavigator告诉ZoomedImage绘制哪个子图像,不如让ZoomedImage在绘制时询问ImageNavigator(通过重写 ...

最新文章

  1. 站在巨人的肩膀上,Adrian与dlib中face_recongnition模块的贡献者Adam的采访部分翻译
  2. 谷歌把安全融入主机芯片
  3. Atlas Cool Application
  4. JavaWeb学习笔记①——Java向下转型在JavaEE中运用——登陆验证
  5. Valve CEO:脑机接口技术可加强游戏体验远超“肉体外设“
  6. fr4速度 微带线_【射频笔记5】传输线理论基础
  7. 体育馆黑名单系统 的设定
  8. 小a与204(牛客寒假算法集训营1题目B)
  9. Linux下配置安装PHP环境
  10. ajax.actionlink使用问题
  11. 解封装(八):av_seek_frame改变播放进度函数
  12. ACE主动对象模式学习
  13. 【muduo源码分析】Buffer类的设计
  14. Linux学习第一篇之Linux系统安装——系统分区
  15. vscode 不能运行h5c3代码_Golang安装与环境搭建并在VSCode里面输出HelloWord
  16. javascript边角知识
  17. 2021-2022年数学建模资料汇总——建模软件篇
  18. Windows Server 2008 RC1标准版
  19. 江苏计算机二级msoffice高级应用,计算机二级考试MSOffice高级应用
  20. java paypal 支付集成_java对接PayPal标准支付操作流程

热门文章

  1. 亲情奉献一些搜集的网站
  2. HDU-1212 Big Number JAVA又出毛病了
  3. 中国九章量子计算机诞生!比最快的超算快一百万亿倍
  4. AI眼中的世界是什么样子?谷歌新研究找到了机器的视觉概念
  5. 中科大“重金”招博士,保底年收入10万,却只面向5校本科生
  6. tms320lf240x 的串行通信接口
  7. mysql client dev_ubuntu下mysql安装(server、client、dev),开启、停止和重启,及常见错误...
  8. wiki多个文件一起导入_wiki.js 使用 postgres 支持中文全文检索
  9. 002_模板 + 数据模型 = 输出
  10. 026_CSS内边距