在 Rebol 中解析此内容的最佳方法
如何从以下 HTML 中提取解析规则中干扰最少的交易收据日期时间? (我希望得到的输出是这样的:“交易收据:04/28/2011 17:03:09”)
<FONT COLOR=DARKBLUE>Transaction Receipt </FONT></TH></TR><TR></TR><TR></TR><TR><TD COLSPAN=4 ALIGN=CENTER><FONT SIZE=-1 COLOR=DARKBLUE>04/28/2011 17:03:09</FONT>
以下内容有效,但我感觉不太好!保证在某处“交易收据”一词后面有一个日期时间(尽管如果我正在执行 grep,我不会进行贪婪匹配)
parse d [
thru {<FONT COLOR=DARKBLUE>Transaction Receipt </FONT></TH></TR><TR></TR><TR></TR><TR><TD COLSPAN=4 ALIGN=CENTER><FONT SIZE=-1 COLOR=DARKBLUE>}
copy t to "</FONT>"
]
How do I extract the transaction receipt datetime with the least bit of noise in my parse rule from the following HTML? (The output I'm looking to get is this: "Transaction Receipt: 04/28/2011 17:03:09")
<FONT COLOR=DARKBLUE>Transaction Receipt </FONT></TH></TR><TR></TR><TR></TR><TR><TD COLSPAN=4 ALIGN=CENTER><FONT SIZE=-1 COLOR=DARKBLUE>04/28/2011 17:03:09</FONT>
The following works but I don't get a good feeling! There is guaranteed to be a datetime following the words Transaction Receipt somewhere (although I wouldn't do a greedy match if I'm doing a grep)
parse d [
thru {<FONT COLOR=DARKBLUE>Transaction Receipt </FONT></TH></TR><TR></TR><TR></TR><TR><TD COLSPAN=4 ALIGN=CENTER><FONT SIZE=-1 COLOR=DARKBLUE>}
copy t to "</FONT>"
]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这更短......
但并不是专门寻找日期时间对。不幸的是,REBOL 认为使用的日期无效......
因此您无法专门搜索它。如果日期是 28/04/2011(并且时间后面有一个空格,但我不确定为什么加载需要它),则以下内容将有效...
嗯。试试这个...
返回:“Transaction Receipt 04/28/2011 17:03:09”
它的工作原理是跳过所有标签,附加剩下的任何文本。
希望有帮助!
This is shorter...
but isn't specifically looking for the datetime pair. And unfortunately REBOL considers the date used an invalid one...
so you can't search for it specifically. If the date was 28/04/2011 (and there was a space after the time, though why it's needed for load I'm not sure), the following would work...
Hmmm. Try this...
That returns: "Transaction Receipt 04/28/2011 17:03:09"
It works by skipping all the tags, appending any text that's left to t.
Hope that helps!
像往常一样及时:如果格式一致,您可以随时尝试显式匹配日期:
Timely as per usual: if the format is consistent, you can always try to explicitly match dates: