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