- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
想要让两个 parent (曾祖 parent )向上还是让两个 child 向下?
<table style="background-color: #008000; border-style: none;" border="0" cellpadding="2" cellspacing="2">
<tr>
<td>
<img height="5" width="5" border="0" src="https://spacer.gif" title="07:00,24hrs: B Shift /.../E704/RS704/Firefighter #2" alt="07:00,24hrs: B Shift /.../E704/RS704/Firefighter #2">
</td>
</tr>
</table>
<img height="2" width="2" border="0" src="https://spacer.gif" alt="">
<img alt="" height="1" width="1" border="0" src="https://spacer.gif">
</td>
<TD ALIGN="RIGHT" VALIGN="TOP" width="17%">
<a href="javascript:void(0)" title="01/15/2013" class="daylink" onClick="return DayClick('01/15/2013');">15</a>
</TD>
<td rowspan="2" width="5">
<img alt="" height="1" width="1" border="0" src="https://spacer.gif">
</td>
</tr>
<tr>
<TD COLSPAN="2">
<TABLE>
<TR>
<TD style="background-color: #41FFB9; " class="calexception">
<a href="javascript:void(0)" onClick="return ShowRemoveExceptionWindow("4A30E80.fre01","3280530");" title="10hrs DetNonEMSStud(10), 07:00 - 17:00" style="color: #000000; text-decoration: none; font-weight: bold;">DetNonEMSStud(10)</a>
</TD>
</TR>
</TABLE>
iOS:
NSString *tutorialsXpathQueryString = @"//table/tr/td";
NSArray *tutorialsNodes = [tutorialsParser searchWithXPathQuery:tutorialsXpathQueryString];
NSLog(@"here is url: %@", tutorialsNodes);
NSMutableArray *newTutorials = [[NSMutableArray alloc] initWithCapacity:0];
for (TFHppleElement *element in tutorialsNodes) {
Tutorial *tutorial = [[Tutorial alloc] init];
[newTutorials addObject:tutorial];
tutorial.url = [element objectForKey:@"style"];
tutorial.title = [[element firstChild] objectForKey:@"title"];
我从 <td>
获取风格和标题来自 <a>
正好我还需要从 <table>
获取样式
我对 obj-c 很陌生,第一次尝试使用 XPATH,任何示例都很棒!
最佳答案
我没有使用过 TFHpple,但如果它支持标准 XPath,您应该能够使用以下 XPath 从 td
转到其包含表:
ancestor::table[1]
此 XPath 选择作为上下文节点的祖先的最近表,因此如果您有此标记:
<table>
<tr><td></td></tr>
<tr>
<td>
<table><tr><td></td></tr></table>
<table>
<tr>
<td>Hey!</td>
</tr>
</table>
</td>
</tr>
</table>
您的上下文节点是带有文本“Hey!”的 td
,那么上面的 XPath 将选择第 6 行的表。
看起来 TFHpple 没有提供在上下文节点上评估 XPath 的方法。鉴于此,一个新的建议 - 每个元素只有一个父元素,因此如果您继续向上查找父元素,您最终应该找到该表。向下移动要困难得多,因为一个元素可以有任意数量的直接子元素,每个元素都有自己的子元素集。我不太了解 Objective-C,但如果您可以确定该表仅向上两级,那么类似这样的操作可能会起作用:
TFHppleElement *table = [[element parent] parent];
如果不能保证表向上两层,那么应该有某种方法通过父级向上查找表。这是伪代码,但希望您能明白:
for (TFHppleElement *element in tutorialsNodes) {
Tutorial *tutorial = [[Tutorial alloc] init];
[newTutorials addObject:tutorial];
tutorial.url = [element objectForKey:@"style"];
tutorial.title = [[element firstChild] objectForKey:@"title"];
TFHppleElement *table = [element parent];
while(table != null && [table tagName] != "table") {
table = [table parent]
}
// table should either be the parent table at this point,
// or null if there was no parent table.
关于html - TFHpple - iOS 中的 xpath - 让两个 parent 站起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14565214/
我正在尝试编写一个非常简单的 iOS 应用程序来解析网页 ( http://arxiv.org/list/cond-mat/recent ) 并显示它的简化版本。我选择使用 TFHpple 来解析这个
我是编程新手,我花了几个小时试图了解如何将 TFHpple 库(或任何 Objective C 库)导入到我的 Swift 代码中。我已经阅读了文档,但我仍然不太明白,谁能给我指出正确的方向? 最佳答
i use this code for html file but it not working how to solve it some one help 它显示此消息/Users/pradeepy
我正在努力从 xPathQuery 中获取任何信息。我使用 Chrome 的开发人员工具获得的链接,并通过右键单击所附屏幕截图中突出显示的行来完成此操作。我正在创建一个基于食谱的应用程序,并且在尝试扩
我想知道你是否可以帮助我。我正在尝试使用 TFHpple 来使用 Swift 1.2 解析 HTML 数据,但在计算 XPath 表达式时遇到问题。我收到以下错误: Optional(https://
想要让两个 parent (曾祖 parent )向上还是让两个 child 向下? 15
我有一个 HTML 字符串,想更改其中的元素,在 img 标记样式中将宽度 = 100% 和高度设为自动,这样当我将它们传递到 Web View 时,图像可以适应 super View 布局。 HTM
代码: NSString *linkStr=@"http://www.voanews.com/content/obama_pledges_aid_to_drought_stricken_farmers
我是一名优秀的程序员,十分优秀!