I was trying to parse from a website using HPPLE. I was successful with the tag but it doesn't seem to work on the other tag. Please advice.
This was the code that I used.
NSData *htmlData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.mywebsite.com/"]];
TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:htmlData];
NSArray *elements = [xpathParser search:@"//tr/td"];
TFHppleElement *element = [elements objectAtIndex:0];
NSString *myTitle = [element content];
NSLog(myTitle);
mLabel.text = myTitle;
[xpathParser release];
[htmlData release];
This is the website source code that I was trying to parse from.
<tr><td bgcolor="#f7f7f7" align="left" width="200" valign="middle" class="font1">Title of Speech</td><td bgcolor="#f7f7f7" align="left" width="150" valign="middle" class="font3">Speaker Name</td><td bgcolor="#f7f7f7" align="left" width="150" valign="middle" class="font3">Date and Time</td><td bgcolor="#f7f7f7" align="center" width="50" valign="middle" class="font3"><a href=""><a href="http://speech.mp4" target="blank"><img src="/Templates/public/images/mp4_300.png" border="0" /></a></a></td
I was intending to parse out the Speech Title, Speaker, Date and Time and name of the mp4 file. But it return a empty string to my outlet label. Please advice.
Regards, Des
Late but maybe useful for others:
Use
NSString *myTitle = [element text];
instead of content
I used hpple for getting the <title>
-Tag of some websites. content
was empty but not text
.
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.