将 Wikipedia 页面部分转换为 NSString Objective-C
我正在编写一些代码,以 NSString 形式检索维基百科页面的一部分。我在网上找到了一个构造的链接,它返回一个部分的原始数据。例如,要获取维基百科页面上“波士顿”的第一部分,您可以访问: http://en.wikipedia.org/ w/index.php?title=波士顿&action=raw§ion=0。
我想要实现的目标是将原始数据转换为可以在正常维基百科页面上看到的内容: http://en.wikipedia.org/wiki/波士顿。
现在,一开始,我想使用正则表达式来解析以 {{
开头并以 }}
结尾的块。然而,这被证明是有问题的,它删除了必要的文本。
然后,我想我可以以某种方式找到 Objective-C 的 wiki 标记到 html 转换器(在线随处可见),但我在那里没有运气。
SO 有几个类似的问题,但似乎没有一个得到明确解决: 使用 NSScanner 问题获取维基百科文章摘要。
那么,继续,有谁知道如何将 wiki 页面解析为 NSString 吗?
先感谢您。
I'm working on some code that retrieves a section of a Wikipedia page as an NSString. I've found a constructed link online that returns the raw data of a section. For instance, to get the first section of the Wikipedia page on 'Boston', you would go to:
http://en.wikipedia.org/w/index.php?title=Boston&action=raw§ion=0.
And what I'm trying to achieve, is to convert that raw data into what can be seen on the normal Wikipedia page: http://en.wikipedia.org/wiki/Boston.
Now, at first, I thought I'd use regular expressions to parse out blocks that start with {{
and end with }}
. However, this proved to be problematic, and it deleted necessary text.
Then, I thought I could somehow find a wiki markup to html converter (present everywhere online) for Objective-C, but I had no luck there.
There are several similar questions on SO, but none of them seem to be clearly resolved: Getting Wikipedia Article Summary using NSScanner Problem.
So, to resume, does anyone know how to parse a wiki page into an NSString?
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 PEG WikiText 解析器,例如 kiwi: https://github.com/AboutUs/kiwi
你可以找到kiwi的解析输出规则在这里: https://github.com/AboutUs/kiwi/blob/master/src/syntax.leg
您需要下载 peg/leg 来编译leg文件:http://piumarta.com/software/peg/
Use a PEG WikiText parser such as kiwi: https://github.com/AboutUs/kiwi
You can find kiwi's parsing output rules here: https://github.com/AboutUs/kiwi/blob/master/src/syntax.leg
You will need to download peg/leg to compile the leg file: http://piumarta.com/software/peg/