首先,我想解析一个 html 并获取一些行
使用 Google Apps 脚本,并显示
"元素类型 "link"必须以匹配的结束标记 "/link ""结束
代码在这里
var response = UrlFetchApp.fetch(url)
var downloadContent = response.getContentText();
var doc = XmlService.parse(downloadContent);
我觉得是因为html用的是html5,所以GAS解析不了,
所以我尝试用其他方法来解析字符串, (逐行阅读并保留我需要的行)
var xml = UrlFetchApp.fetch(url).getContentText();
但是GAS没有Scanner,我该怎么办?
其实我想去这个url“https://www.ptt.cc/bbs/gossiping/index.html”
并在
中获取信息<div class="r-ent">
...
</div>
最佳答案
Google Apps 脚本是 JavaScript,因此您可以使用 split() 方法将文本内容按换行符拆分为多行。
var text = UrlFetchApp.fetch(url).getContentText();
var lines = text.split(/\r?\n/);
Logger.log(lines);
关于javascript - Google Apps 脚本可以逐行读取 txt 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44432370/