如何解析文本和图像

时间:2011-08-11 02:41:31

标签: android jsoup

  

可能重复:
  How to get text from this html page with jsoup?

我正在尝试使用JSOUP解析此HTML页面中的图像和文本。

http://movies.ign.com/articles/100/1002569p1.html

这是我试图用来检索它的代码。但我没有得到任何返回TextView。

“Doc”日志正在从html页面记录事物,因此它的连接。我只是因为某些原因没有收到任何文字。

public class HtmlparserExampleActivity extends Activity {
String outputtext;
  TagFindingVisitor visitor;
  Parser parser = null;
private static final String TAG = "TVGuide";



TextView outputTextView;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    outputTextView = (TextView)findViewById(R.id.outputTextView);
    String id = "main-article-content";
    Document doc = null;

    try {
        doc = Jsoup.connect("http://movies.ign.com/articles/100/1002569p1.html").get();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    Log.i("DOC", doc.toString().toString());
    Elements elementsHtml = doc.getElementsByTag(id);  
    String[] temp1 = new String[99];    
    int i =0;
    for(Element element: elementsHtml)
    {
        Log.i("data: ", element.text());
        temp1[1] = element.text();  
        outputTextView.setText(temp1[1]);
        i++;


    }




}
}

1 个答案:

答案 0 :(得分:0)

试试这个。可能在你的代码执行之前你的页面没有加载到doc中

doc=Jsoup.parse(new URL("http://movies.ign.com/articles/100/1002569p1.html"),10000);