【发布时间】:2017-01-29 07:49:31
【问题描述】:
Google 应用程序脚本获取 HTTP 响应内容文本。摘录如下。
<p style="text-align: left;"><span style="background-color: rgb(242, 195, 20);"><span style="color: rgb(192, 80, 77);">Disclaimer:</span></span><span style="background-color: rgb(255, 255, 255);">Please note,</span><a href="http://www.g00gl3.com"><span style="background-color: rgb(255, 255, 255);">http://www.g00gl3.com</span></a><span style="background-color: rgb(255, 255, 255);"> or </span><a href="http://www.g00gl3.com"><span style="background-color: rgb(255, 255, 255);">www.G00gl3.com</span></a><span style="background-color: rgb(255, 255, 255);"> is only video embedding websites. All of the videos found here come from 3rd party video hosting sites. We do not host any of the videos. Please contact to appropriate video hosting site for any video removal.</span></p>
<div style="text-align: center;"><strong><span style="background-color: rgb(255, 255, 255);">Dailymotion <br><br></span></strong></div>
<div style="text-align: center;"><iframe src="http://www.dailymotion.com/embed/video/foo1234567890bar? syndication=202279" width="640" height="360" frameborder="0"></iframe></div>
<div style="text-align: center;"><strong><span style="background-color: rgb(255, 255, 255);">Alternate Video <br><br></span></strong></div>
<div style="text-align: center;"><iframe src="http://hqq.tv/player/embed_player.php?vid=1234567890&autoplay=no" width="720" height="450" frameborder="0"></iframe></div>
从这段摘录中需要提取标题(Dailymotion 或备用视频)和 iframe。
仅匹配 iframe 已完成。
/<iframe(.*)\/iframe>/g
现在预期是
Dailymotion <br><br></span></strong></div>
<div style="text-align: center;"><iframe src="http://www.dailymotion.com/embed/video/foo1234567890bar? syndication=202279" width="640" height="360" frameborder="0"></iframe>
和
Alternate Video <br><br></span></strong></div>
<div style="text-align: center;"><iframe src="http://hqq.tv/player/embed_player.php?vid=1234567890&autoplay=no" width="720" height="450" frameborder="0"></iframe>
任何人都可以帮助编写正则表达式以仅在上面获取。
【问题讨论】:
-
也许您可以使用 DOM 解析器而不是正则表达式。正则表达式不能很好地处理嵌套的 XML。
-
感谢@TimBiegeleisen 的回复。需要检查 Google Apps 脚本是否有 DOM 解析器。
标签: javascript regex google-apps-script