Need help to convert following html to csv with me

2019-09-01 13:48发布

<html>
<head>
<title>My Headline</title>
<meta name="targetUrl" value="xyz.html?sym=abc"/>
<meta name="summary" value="A & B"/>
</head>
<body>
abc abc, pqr, xyz, rst tsd, prrrr, qqqqqqq, oooooo, opop opop, rtrttrt rtrtrtrt
</body>
</html>

The body tag should be changed to csv so the output should be like this :

abc abc, pqr, xyz, rst tsd, prrrr, qqqqqqq, oooooo, opop opop, rtrttrt rtrtrtrt

if i try @Jim's solution

parsing exception occurs for meta tags as they have special characters

1条回答
别忘想泡老子
2楼-- · 2019-09-01 14:10

Here's an XSLT1 solution

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="text"/>
  <xsl:template match="@*|node()"><xsl:apply-templates select="@*|node()"/></xsl:template>
  <xsl:template match="body"><xsl:value-of select="text()"/></xsl:template>
</xsl:stylesheet>

Note that since your input contains a newline before and after the data, it will be written to the output as well, resulting in a blank first and lasst line.

查看更多
登录 后发表回答