简体   繁体   中英

Cant parse HTML using HTMLCleaner

I try to parse html follow this link;

http://thuoc.vn/Default.aspx?Mod=ViewDrugs&DrugsID=52016

I want to read some content in this code

 <div class="tabContent" id="PillContent" style="display: block;"> <div class="headerinfo">Chỉ định:</div> Viêm mũi dị ứng như hắt hơi, sổ mũi, ngứa mũi, ngạt mũi kèm kích ứng, ngứa họng, ho, giảm các triệu chứng mề đay mãn tự phát. <div class="headerinfo">Chống chỉ định:</div> Quá mẫn với thành phần thuốc. <div class="headerinfo">Chú ý đề phòng:</div> Trẻ < 12t. Có thai và cho con bú: không nên dùng <div class="headerinfo">Tác dụng ngoài ý:</div> Hiếm cảm giác mệt mỏi, khô miệng, nhức đầu, rất hiếm: nổi mẩn và phản vệ. <div class="headerinfo">Liều lượng:</div> Người lớn và trẻ >= 12t: uống 1 viên ngày 1 lần. </div> 

But I cant read anything in this.

My code. I just try to read everything in tag div.

HtmlCleaner cleaner = new HtmlCleaner();
    TagNode node = null;
    try {
        node = cleaner
                .clean(new URL(
                        "http://thuoc.vn/Default.aspx?Mod=ViewDrugs&DrugsID=35318"));
        for (Object o : node.evaluateXPath("//div")) {

            System.out.println(((TagNode) o).getText());
        }
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

`

final HtmlCleaner mCleaner = new HtmlCleaner();   
CleanerProperties props = mCleaner.getProperties();  
    props.setAllowHtmlInsideAttributes(true);  
    props.setAllowMultiWordAttributes(true);  
    props.setRecognizeUnicodeChars(true);  
    props.setOmitComments(true);      
 /*url from were data to be fetched*/  
String mSiteUrl="http://www.example.com";   
String mXPath="//div";   
//TagnNode for storing data received from url  
final TagNode mGetDataFromUrl;   //Establish connection   URL
url=new URL(mSiteUrl);   final URLConnection
mCCon=url.openConnection();   mGetDataFromUrl=mCleaner .clean(new   
InputStreamReader(mCCon.getInputStream()));   //get to xpath from
were data is to be retrieve    Object[]
mPageData=mGetDataFromUrl.evaluateXPath(mXPath);   //validate object
if(mPageData.length>0) {
     TagNode mXPathParsedData = (TagNode) mPageData[0];  
     // all text in div is in mData   
     Strign mData=mXPathParsedData .getText().trim();   }

` This one way hope this help you! thanks.

 <div class="tabContent" id="PillContent" style="display: block;"> <div class="headerinfo" style="font-weight: bold;color: #F14609;font-size: 12px;margin-bottom: 5px;margin-top: 15px;">Chỉ định:</div> Viêm mũi dị ứng như hắt hơi, sổ mũi, ngứa mũi, ngạt mũi kèm kích ứng, ngứa họng, ho, giảm các triệu chứng mề đay mãn tự phát. <div class="headerinfo" style="font-weight: bold;color: #F14609;font-size: 12px;margin-bottom: 5px;margin-top: 15px;">Chống chỉ định:</div> Quá mẫn với thành phần thuốc. <div class="headerinfo" style="font-weight: bold;color: #F14609;font-size: 12px;margin-bottom: 5px;margin-top: 15px;">Chú ý đề phòng:</div> Trẻ < 12t. Có thai và cho con bú: không nên dùng <div class="headerinfo" style="font-weight: bold;color: #F14609;font-size: 12px;margin-bottom: 5px;margin-top: 15px;">Tác dụng ngoài ý:</div> Hiếm cảm giác mệt mỏi, khô miệng, nhức đầu, rất hiếm: nổi mẩn và phản vệ. <div class="headerinfo" style="font-weight: bold;color: #F14609;font-size: 12px;margin-bottom: 5px;margin-top: 15px;">Liều lượng:</div> Người lớn và trẻ >= 12t: uống 1 viên ngày 1 lần. </div> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM