2
我試圖使用HPPLE從網站進行解析。我在標籤上取得了成功,但似乎無法在其他標籤上使用。請指教。無法使用Hpple從網站獲取內容
這是我使用的代碼。
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];
這是我試圖解析的網站源代碼。
<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
我打算分析演講標題,演講者,日期和時間以及mp4文件的名稱。但它將一個空字符串返回給我的插座標籤。請指教。
問候,德