【发布时间】:2019-09-22 18:10:24
【问题描述】:
我只需要在获取页面后保留它的正文内容。以下代码不起作用(也就是说,html 变量在 .replace 代码行之后不会更改,正如我从日志中看到的那样)。怎么了?
var response = UrlFetchApp.fetch('https://stackoverflow.com/questions/58049531/another-importxml-returning-empty-content');
var html=response.getContentText();
html=html.replace(/.*(<body[^>]*)/m, '$1');
html=html.replace(/<\/body>.*/m, '</body>');
Logger.log(html);
【问题讨论】:
-
解释不起作用
-
我已经更新了问题。两个 replace 调用并没有改变 html 变量,就好像它们无法找到 body 标记的打开和关闭一样。
-
尝试
[^]而不是. -
比如
html = html.match(/<body[\s\S]+<\/body>/)[0]呢?
标签: regex google-apps-script urlfetch