我需要先获取文本内容<p>
这是的孩子<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 https://stackoverflow.com/questions/17798417/hxt-select-a-node-by-position-with-hxt-in-haskell?answertab=active#tab-top)
它可能是这样的XPath http://www.w3.org/TR/xpath/
import "hxt-xpath" Text.XML.HXT.XPath.Arrows (getXPathTrees)
...
xp = "//div[@class='about']/p[1]"
parseDescription = getXPathTrees xp >>> getChildren >>> getText
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)