我试图获取img标记的img属性,该属性将属性itemprop设置为某些值。
好的,我得到了img标记,我能够根据我今天早些时候在这里问的问题(这里显然没有文本)提取内部文本,但是我找不到任何可以帮助我返回src属性值的东西。
(:require [net.cgrand.enlive-html :as e])
(defn getbyitemprop
"Extract node content from HTML"
[html value]
(e/select-nodes* (e/html-snippet html)
[(e/attr= :itemprop value) e/text-node]))这就得到了元素的内部文本,我把它作为一个参数传递。
发布于 2013-09-20 13:17:13
在本例中,您需要包含属性和内容的标记,因此您将删除选择器的net.cgrand.enlive-html/text-node部分。
(defn getbyitemprop
"Extract node content from HTML"
[html value]
(e/select-nodes* (e/html-snippet html)
[(e/attr= :itemprop value)]))
(getbyitemprop
"<p itemprop=\"description\" src=\"testvalue\"> Some content I want to extract </p>"
"description")
;=> ({:tag :p,
; :attrs {:src "testvalue", :itemprop "description"},
; :content (" Some content I want to extract ")})这适用于html的动态字符串,如果您希望对文件或资源进行更一般的转换,请查看文档 for deftemplate和defsnippet。
https://stackoverflow.com/questions/18916797
复制相似问题