sups
sups

Reputation: 113

parse html page

i want to parse 1 url and afterwords i want to access some data from that.

try {
        Document doc = Jsoup.connect("http://abc.com/en/currency/default.aspx").get();//abc is for example as i cant put site name
        Elements td = doc.select("ctl00_ContentPlaceHolder1_currencylist_rptCurrencyList_ctl01_trList"); //this is the name of table row in html page i will show html page snippet also
        String temp=td.val();
        info.setText(temp);
    } 
     catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } 

snippet of html page which i want to parse is as follows

       <tr id="ctl00_ContentPlaceHolder1_currencylist_rptCurrencyList_ctl01_trList">
<td width="400px" class="CurrencyListItems">             
         UK POUND
         </td>
<td width="60px;" class="CurrencyListItemsIN" align="center">
         5.72
         </td>
<td width="150px;" class="CurrencyListItemsLast">
           <table cellspacing ="0" cellpadding ="0" width="100%">
                   <tr>
                     <td class="CurrencyListBANKNOTES" align="center">                         
                     5.625
                     </td>
                     <td class="CurrencyListBANKNOTES2" width="75px" align="center">

                     5.75
                     </td>
                   </tr>
            </table>
         </td>

i want from above html UK pound ,5.625,5.75 i tried above code,but the thng is it is not parsing URL only its jus coming out if try

Upvotes: 1

Views: 271

Answers (1)

confucius
confucius

Reputation: 13327

try this:

Element tr = doc.getElementById("ctl00_ContentPlaceHolder1_currencylist_rptCurrencyList_ctl01_trList");

try

String contents = tr.text().trim();
contents = contents.replaceAll("\\s+"," "); 
contents = contents. replaceAll("\\<.*?>","-");
String []values = contents.split("-");

or

Elements elements = tr.select("*");
for (Element element : elements) {
    System.out.println(element.ownText());
}

Upvotes: 2

Related Questions