gpt4 book ai didi

haskell - HXT 获取第一个元素 : refactor weird arrow

转载 作者:行者123 更新时间:2023-12-02 10:19:05 27 4
gpt4 key购买 nike

我需要获取第一个<p>的文本内容这是<div class="about">的 child ,编写了以下代码:

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 )

最佳答案

可能是这样的 XPath

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

...

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

parseDescription = getXPathTrees xp >>> getChildren >>> getText

关于haskell - HXT 获取第一个元素 : refactor weird arrow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23310769/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com