我正在研究一个 groovy 脚本,它将获取所有本地 html 文件并解析其中的某些标签。我尝试使用 html clean 之类的东西,但它不起作用。我试图阅读每一行,但只有当我需要的东西在 1 行时才有效。我在 github 上有这个脚本,https://github.com/jrock2004/johns-octopress-scripts/blob/master/convertCompiledPosts/convertPosts.groovy。感谢您的任何意见
编辑:所以我越来越近了。我现在有这个代码
def parser = new org.cyberneko.html.parsers.SAXParser()
new XmlParser( parser ).parse( curFile+ "/index.html" ).with { page ->
page.'**'.DIV.grep { it.'@class'?.contains 'entry-content' }.each {
println it
println "--------------------------------"
}
}
它打印的是
DIV[attributes={class=entry-content}; value=[P[attributes={}; value=[As an automation developer, I have learned how to write code in Java. When I am having an issue, one of the nice things that you can do is debug your code, line by line. For the longest I had wished that something like this existed in PHP. I have come to find out that you can actually debug code, like I do in Java. This is such a helpful task because I do not have to waste time using var_dump and such on variables or results. In your apache/php server you need to install and or enable something called, A[attributes={href=http://xdebug.org/}; value=[Xdebug]], . I will work on a tutorial on how to use xdebug while writing code in Sublime Text 2. So keep an eye out on my blog and or, A[attributes={href=http://www.youtube.com/jrock20041}; value=[YouTube]], channel for this tutorial.]]]]
所以基本上我想要的是我将包含 div 中的 html 元素的文本与类 entry-content 结合起来。如果您想查看该页面,可以在这里找到——http: //jcwebconcepts.net/blog/2013/02/02/xdebug/
谢谢你的帮助