2

<p>の子であるfirst のテキスト コンテンツを取得する必要があるため<div class="about">、次のコードを記述しました。

tagTextS :: IOSArrow XmlTree String
tagTextS = getChildren >>> getText >>> arr stripString

parseDescription :: IOSArrow XmlTree String
parseDescription =
  (
   deep (isElem >>> hasName "div" >>> hasAttrValue "id" (== "company_about_full_description"))
   >>> (arr (\x -> x) /> isElem  >>> hasName "p") >. (!! 0) >>> tagTextS
  ) `orElse` (constA "")

これを見てください。これarr (\x -> x)がなければ、結果を出すことができませんでした。

  • より良い書き方はありparseDescriptionますか?
  • 別の質問は、なぜ前後に括弧が必要なのarrですhasName "p"か? (私は実際にこの解決策を見つけましたhere
4

2 に答える 2

4

XPathでこのようなものになる可能性があります

import "hxt-xpath" Text.XML.HXT.XPath.Arrows (getXPathTrees)

...

xp = "//div[@class='about']/p[1]"

parseDescription = getXPathTrees xp >>> getChildren >>> getText
于 2014-04-26T14:22:00.380 に答える