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