admin管理员组文章数量:1333710
First, I want parse a html and fetch some line
with Google Apps Script, and it's showed
" The element type "link" must be terminated by the matching end-tag "/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,
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?
In fact, I want to go this url ".html"
and fetch information in
<div class="r-ent">
...
</div>
First, I want parse a html and fetch some line
with Google Apps Script, and it's showed
" The element type "link" must be terminated by the matching end-tag "/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,
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?
In fact, I want to go this url "https://www.ptt/bbs/gossiping/index.html"
and fetch information in
<div class="r-ent">
...
</div>
Share
Improve this question
asked Jun 8, 2017 at 9:51
JimmyHoJimmyHo
2891 gold badge5 silver badges14 bronze badges
2
- You might find Spencer Easton's new library useful for parsing HTML: github./Spencer-Easton/Apps-Script-htmlparser2-library – Andrew Roberts Commented Jun 8, 2017 at 12:23
- I will follow this git, thanks! @AndrewRoberts – JimmyHo Commented Jun 9, 2017 at 4:01
1 Answer
Reset to default 9Google Apps Script is JavaScript so you can use the split() method to split the text content into multiple lines by the newline character.
var text = UrlFetchApp.fetch(url).getContentText();
var lines = text.split(/\r?\n/);
Logger.log(lines);
本文标签: javascriptCan Google Apps Script read txt line by lineStack Overflow
版权声明:本文标题:javascript - Can Google Apps Script read txt line by line? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742339618a2456331.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论