无法在android中使用AsyncTask从url获取内容?
正在尝试从下载内容无法在android中使用AsyncTask从url获取内容?,android,android-asynctask,web-content,Android,Android Asynctask,Web Content,正在尝试从下载内容 公共类下载任务扩展了异步任务{ @凌驾 受保护的字符串背景(字符串…字符串){ 字符串strPageHTML=“”; URL objURL; HttpURLConnection objHttpURLConn=null; 试一试{ objURL=新URL(strURLs[0]); objHttpURLConn=(HttpURLConnection)objURL.openConnection(); InputStream objInputStream=objhttpurlcon.
公共类下载任务扩展了异步任务{
@凌驾
受保护的字符串背景(字符串…字符串){
字符串strPageHTML=“”;
URL objURL;
HttpURLConnection objHttpURLConn=null;
试一试{
objURL=新URL(strURLs[0]);
objHttpURLConn=(HttpURLConnection)objURL.openConnection();
InputStream objInputStream=objhttpurlcon.getInputStream();
InputStreamReader objInputStreamReader=新的InputStreamReader(objInputStream);
int intData=objInputStreamReader.read();
while(intData!=-1){
char chrCurrent=(char)intData;
strPageHTML+=chrCurrent;
intData=objInputStreamReader.read();
}
//Log.i(“页面:”,strPageHTML);
返回strPageHTML;
}捕获(例外e){
e、 printStackTrace();
返回null;
}
}
}
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
字符串strPageHTML=null;
DownloadTask objDT=新的DownloadTask();
imgvwCeleb=findviewbyd(R.id.imgvwCelebrity);
试一试{
strPageHTML=objDT.execute(“https://www.forbesindia.com/lists/2019-celebrity-100/1819/all).get();
字符串[]strarrPageHTML=strPageHTML.split(“”);
字符串strRequiredHTML=strarrPageHTML[0];
....
}
问题是,它缺少我需要的主要内容
//getting everything above this
<!-- Celebrity Consumption -->
<div class="list-consumption">
<div class="celeb-grid-wrap flex-celeb" id="list_rank">
//#### Here should be the content that I need.......
</div>
</div>
<!-- <div class="note-section">
<p>
<span>NOTE :</span>
Click here for Methodology and Disclaimer
</p>
</div>-->
//getting everything below this
//获取以上所有内容
//####这里应该是我需要的内容。。。。。。。
//一切都在这下面
缺少的是名人名单(请查看上述链接的页面来源)。内容丢失是因为它是通过Ajax动态加载的吗?还是我做错了什么?异步任务不受欢迎。我只是在学习教程,我不知道还可以使用什么。没关系,让人们知道是很有用的,因为可能有更好或更简单的方法
//getting everything above this
<!-- Celebrity Consumption -->
<div class="list-consumption">
<div class="celeb-grid-wrap flex-celeb" id="list_rank">
//#### Here should be the content that I need.......
</div>
</div>
<!-- <div class="note-section">
<p>
<span>NOTE :</span>
Click here for Methodology and Disclaimer
</p>
</div>-->
//getting everything below this