2
我是F#的全新品牌,所以我很抱歉如果我使用不正确的名称作为事情。使用管道向前嵌套序列
我试图使用F#分析一个网页看起来是这样的:
<!--This is simplified, in reality there are more divs, anchors etc. -->
<html>
<body>
<div class="pr-single"><a href="http://google.ca">Google</a></div>
<div class="pr-single"><a href="http://apple.com">Apple</a></div>
<div class="pr-single"><a href="http://microsoft.com">Microsoft</a></div>
</body>
</html>
我已经声明的类型
type PromoterPage = FSharp.Data.HtmlProvider<"http://somewebpage.com">
现在我试图让页面上所有链接的列表。我的思维过程是:
- 获取所有类名外的div
- 获取所有这些div的后代
- 收集这些后代成平面列表
- 过滤该列表下降到仅
<a>
标签
我在此尝试如下:
let GetFirst (page:PromoterPage) =
page.Html.Descendants()
|> Seq.filter(fun n -> n.HasClass("pr-single")) //Find the divs
|> Seq.map(fun n -> n.Descendants()) //Get the descendants
|> Seq.collect(fun n -> n |> Seq.where(fun m -> m.HasName("a")) //Filter and collect the anchors
这个问题似乎是你不能嵌套Seq
函数或我做得不对。我收到的错误:
Incomplete values or function definition. If this is an expression, the body of the expression must be indented to the same column as the keyword.
我可以巢Seq
功能,我想在这里的呢?我是否以错误的方式思考这个问题?
哇,这很尴尬。 :) 谢谢! – JoshVarty