How to parse Text and Images from this [duplicate]
Possible Duplicate:
How to get text from this html page with jsoup?
I am trying to parse the images and text from this HTML page using JSOUP.
http://movies.ign.com/articles/100/1002569p1.html
Here is the code i am trying to use to retreive it. But i get nothing returned into the TextView.
The "Doc" Log is logging things from the html page, so its connecting. Im just not receiving any text for some reason.
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.setTex开发者_如何学编程t(temp1[1]);
i++;
}
}
}
Try this.May be your page is not loaded in doc before your code is executing
doc=Jsoup.parse(new URL("http://movies.ign.com/articles/100/1002569p1.html"),10000);
精彩评论