当前位置: 首页 > 工具软件 > HtmlCleaner > 使用案例 >

htmlcleaner 抓取内容不带html标签,使用HTMLCleaner解析文本问题 - 文本开头的空格

仲皓君
2023-12-01

我试过android:gravity但什么也没有发生。

请帮助。

这里是我的代码:

private class SiteParser extends AsyncTask {

protected String doInBackground(String... arg) {

String output = null;

try {

HtmlHelper hh = new HtmlHelper(new URL(arg[0]));

List news = hh.getnewsByClass("TextoPrint");

for (Iterator iterator = newss.iterator(); iterator

.hasNext();) {

TagNode divElement = (TagNode) iterator.next();

output = divElement.getText().toString();

}

} catch (Exception e) {

e.printStackTrace();

}

return output;

}

protected void onPostExecute(String output) {

Bundle bundle=new Bundle();

bundle.putString("body",output);

Intent mainIntent = new Intent(act, MyView.class);

mainIntent.putExtras(bundle);

startActivity(mainIntent);

act.finish();

}

}

public class HtmlHelper {

TagNode rootNode;

public HtmlHelper(URL htmlPage) throws IOException, XPatherException {

HtmlCleaner cleaner = new HtmlCleaner();

rootNode = cleaner.clean(htmlPage);

}

List getnewsByClass(String Classname){

List newsList = new ArrayList();

TagNode divElements[] = rootNode.getElementsByName("div", true);

for (int i = 0; divElements != null && i < divElements.length; i++) {

String classType = divElements[i].getAttributeByName("id");

if (classType != null && classType.equals(Classname)) {

newsList.add(divElements[i]);

}

}

return newsList;

}

}

+0

这将有助于看到布局XML。 –

 类似资料: