Tfhpple +xpath Analysis of Wanfang data knowledge Platform

Source: Internet
Author: User

Try it out and basically fit all the results of the search.

-(void) viewdidload{[Super Viewdidload];        Additional setup after loading the view, typically from a nib.    Get Data Nsurl *url=[nsurl urlwithstring:@ "Http://s.g.wanfangdata.com.cn/Paper.aspx?q=hiv"];    Nsurlrequest *request=[nsurlrequest Requestwithurl:url];        NSData *data=[nsurlconnection sendsynchronousrequest:request Returningresponse:nil Error:nil];        Analytic data tfhpple *hpple=[tfhpple Hpplewithhtmldata:data]; The shorter the XPath string, the better, but you can filter out the results that meet the requirements//xpath Tutorial: http://www.w3cschool.cn/index-14.html nsstring *xpathstr [email prote CTED] "//div/ul/li [@class = ' title_li ']/A [Not (@class)]";//Parse title NSString *XPATHSTR2 [email protected] "//div/ul/l    I [@class = ' Zi '] ";//Analysis Introduction Nsarray *arr=[hpple SEARCHWITHXPATHQUERY:XPATHSTR];    Nsarray *arr2=[hpple SEARCHWITHXPATHQUERY:XPATHSTR2];    NSLog (@ "%@", arr2);    This array will have the desired value Alltilte=[[nsmutablearray alloc]init];    Alltext=[[nsmutablearray Alloc]init];    Alltilte = [self Savearry:arr]; AlLtext = [self savealltext:arr2];        for (int i=0;i<alltilte.count;i++) {NSLog (@ "title%@", Alltilte[i]);    NSLog (@ "Introduction%@", Alltext[i]);    } [Self.tableview Registerclass:[uitableviewcell class] forcellreuseidentifier:@ "Cell"]; }-(Nsmutablearray *) Savealltext:(Nsarray *) _arry{for (tfhppleelement *tmp in _arry) {NSString * string =[t                MP Raw];        Nsrange range;        Nsrange Range2;        Range = [string rangeofstring:@ "<br/>"];                string = [string substringToIndex:range.location];                                                           NSString *temp =[string stringbyreplacingoccurrencesofstring:@ "<li class=\" zi\ ">"        withstring:@ ""];                                              Temp =[temp stringbyreplacingoccurrencesofstring:@ "<font color=\" red\ ">"        withstring:@ ""];                                              Temp =[temp stringbyreplacingoccurrencesofstring:@ "</font>"withstring:@ ""]; Temp =[temp stringbyreplacingoccurrencesofstring:@ "<li class=\" Zi\ ">" W        ithstring:@ ""];    [Alltext addobject:temp]; } return alltext;} -(Nsmutablearray *) Savearry: (Nsarray *) _arry{for (tfhppleelement *tmp in _arry) {NSString * string =[t        MP Raw];        Nsrange range;        Nsrange Range2;        Range = [string rangeofstring:@ "</a>"];        string = [string substringToIndex:range.location];        NSString *temp =[string stringbyreplacingoccurrencesofstring:@ "<font color=\" red\ ">" withString:@ ""];        Temp=[temp stringbyreplacingoccurrencesofstring:@ "</font>" withstring:@ ""];        Range = [string rangeofstring:@ ">"];        Range2 = [String rangeofstring:@ "img"];           if (range.length!=0&&range2.length==0) {string = [temp substringfromindex:range.location+1];        [Alltilte addobject:string]; }} REturn Alltilte;} 



Tfhpple +xpath Analysis of Wanfang data knowledge Platform

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.