We help IT Professionals succeed at work.
Get Started

HTML Parsing

jazk0 asked
Last Modified: 2013-11-23
Hello everyone i have a function which made an post request and getting the response html in string

String sourceUrlString="http://www.url.com";
String result = postData(sourceUrlString);

public String postData(String url){  
	    // Create a new HttpClient and Post Header  
	    HttpClient httpclient = new DefaultHttpClient();  
	    HttpPost httppost = new HttpPost(url);  

    	try {  
    		// Add your data  
    		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);  
	    	nameValuePairs.add(new BasicNameValuePair("p", "bm02new"));
	    	nameValuePairs.add(new BasicNameValuePair("town", "¿¿¿¿¿"));
	    	nameValuePairs.add(new BasicNameValuePair("addr", ""));
	    	nameValuePairs.add(new BasicNameValuePair("code", "0"));
	    	nameValuePairs.add(new BasicNameValuePair("bank", "0"));
	    	nameValuePairs.add(new BasicNameValuePair("submit", "ok")); 
	    	httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));  

	    	// Execute HTTP Post Request  
	    	HttpResponse response = httpclient.execute(httppost);
	    	InputStream is = response.getEntity().getContent();
	    	BufferedInputStream bis = new BufferedInputStream(is);
	    	ByteArrayBuffer baf = new ByteArrayBuffer(20);

	    	 int current = 0;  
	    	 while((current = bis.read()) != -1){  
	    	/* Convert the Bytes read to a String. */  
	    	String text = new String(baf.toByteArray()); 
	    	return text;

    	} catch (ClientProtocolException e) {  
    		// TODO Auto-generated catch block  
    	} catch (IOException e) {  
    		// TODO Auto-generated catch block  
		String text = null;
		return text;

Open in new window

the html is like that

<table cellspacing="0" cellpadding="2" border="0">
<tr bgcolor="#3493e0">
 <td width="90">
<img height="1" width="90" border="0" src="space.gif"><br>
<span class="smallw"><b>¿¿¿¿¿¿¿¿<br> ¿¿¿¿¿</b></span>
<td><img height="1" width="10" border="0" src="space.gif"></td>
 <td width="160"><img height="1" width="160" border="0" src="space.gif"><br>
<span class="smallw"><b>¿¿¿¿¿</b></span>
<td><img height="1" width="10" border="0" src="space.gif"></td>
<td width="145"><img height="1" width="145" border="0" src="space.gif"><br>
<span class="smallw"><b>¿¿¿¿¿</b></span></td>
<td><img height="1" width="10" border="0" src="space.gif">
<td width="125"><img height="1" width="125" border="0" src="space.gif"><br>
<span class="smallw"><b>¿¿¿¿¿¿, ¿¿¿¿¿¿¿¿¿<br> 14.06.2010, 18:00</b></span>
<tr height="42" bgcolor="#eeeeee">
<td><span class="normal">[b]DATA1[/b]</span></td>
<td><span class="normal">[b]DATA2[/b]</span></td>
<td><span class="normal">[b]DATA3[/b]</span></td>
<td align="center"> 
<span class="small"><a href="[b]URLDATA[/b]" onclick="window.open('','bmDetails056118','toolbar=no,location=no,menubar=no,directories=no,status=no,resizable=no,scrollbars=no,width=400,height=600, titlebar=no');" target="bmDetails056118"><img border="0" src="/magnifier.gif" alt="¿¿¿¿¿¿"></a></span></td>
<tr height="42" bgcolor="">
<td><span class="normal">[b]DATA1[/b]</span></td>
<td><span class="normal">[b]DATA2[/b]</span></td>
<td><span class="normal">[b]DATA3[/b]</span></td>
<td align="center"> <span class="small"><a href="[b]URLDATA[/b]" onclick="window.open('','bmDetails643001','toolbar=no,location=no,menubar=no,directories=no,status=no,resizable=no,scrollbars=no,width=400,height=600, titlebar=no');" target="bmDetails643001"><img border="0" src="/magnifier.gif" alt="¿¿¿¿¿¿"></a></span></td>

Open in new window

I need a way to get DATA1 DATA2 DATA3 and URLDATA into vector array

I need the code for android app but it is Java
Watch Question
This problem has been solved!
Unlock 6 Answers and 9 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE