[英]Can Google Apps Script read txt line by line?
First, I want parse a html and fetch some line 首先,我想解析一个HTML并获取一些行
with Google Apps Script, and it's showed 使用Google Apps脚本,它就显示出来了
" The element type "link" must be terminated by the matching end-tag "/link " " “元素类型”链接“必须由匹配的结束标记”/ link“终止”
and code here 和代码在这里
var response = UrlFetchApp.fetch(url)
var downloadContent = response.getContentText();
var doc = XmlService.parse(downloadContent);
I think because the html use html5, that GAS can't parsing, 我认为因为html使用html5,GAS无法解析,
so I try otherwise method to parsing string, (read line by line and keep lines which I need) 所以我尝试使用其他方法来解析字符串,(逐行读取并保留我需要的行)
var xml = UrlFetchApp.fetch(url).getContentText();
but GAS hasn't Scanner, and how can I do? 但是GAS没有Scanner,我该怎么办?
In fact, I want to go this url " https://www.ptt.cc/bbs/gossiping/index.html " 事实上,我想去这个网址“ https://www.ptt.cc/bbs/gossiping/index.html ”
and fetch information in 并获取信息
<div class="r-ent">
...
</div>
Google Apps Script is JavaScript so you can use the split() method to split the text content into multiple lines by the newline character. Google Apps脚本是JavaScript,因此您可以使用split()方法通过换行符将文本内容拆分为多行。
var text = UrlFetchApp.fetch(url).getContentText();
var lines = text.split(/\r?\n/);
Logger.log(lines);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.