google app脚本超出内存限制 [英] google app script Exceeded memory limit
问题描述
也许这个问题已经问过了,但这不能解决我的问题.
May be this question already asked, but that won't solve my problem.
我尝试使用google app script
将数据保存到google spreadsheet
中.但是显示超出内存限制错误.
I try to save data's into google spreadsheet
using google app script
. But it shows Exceeded memory limit error.
遵循我的代码:
//new
function getNewTitle() {
var url = "https://www.reddit.com/r/DigitalMarketing.rss?limit=100&after=0";
var fromText = '</updated><title>';
var toText = '</title>';
var content = UrlFetchApp.fetch(url).getContentText();
var scraped = Parser.data(content).from(fromText).to(toText).iterate();
return scraped;
}
function getNewContent() {
var url = "https://www.reddit.com/r/DigitalMarketing.rss?limit=10&after=0";
var content = UrlFetchApp.fetch(url).getContentText();
var document = XmlService.parse(content);
var root = document.getRootElement();
var atom = XmlService.getNamespace('http://www.w3.org/2005/Atom');
Logger.log(atom);
var fromText = '<content type="html"><!-- SC_OFF --><div class="md"><p>';
var toText = '</div>';
var scraped = Parser.data(content).from(fromText).to(toText).iterate();
return scraped;
}
function getNewLink() {
var url = "https://www.reddit.com/r/DigitalMarketing.rss?limit=10&after=0";
var fromText = '<link href="';
var toText = '" /><updated>';
var content = UrlFetchApp.fetch(url).getContentText();
var scraped = Parser.data(content).from(fromText).to(toText).iterate();
return scraped;
}
function SAVE_DATA() {
var sheet = SpreadsheetApp.openById('1No3m_FnhyxIaxj2zSlbHrg8HLBJULGQ2bda65hpKlyY').getSheetByName('sample');
var content = getNewContent();
var title = getNewTitle();
var link = getNewLink();
Logger.log(title[1]);
for(var i =0; i < title.length; i++) {
sheet.appendRow([ 'Reddit','wordpress', title[i], link[i], content[i]]);
}
}
//new
在我上面的代码中,试图保存url
中的数据.
In my above code am tried to save the data from url
.
但是我得到
Exceeded memory limit
错误.
在我的日志中,我收到了此消息
In my Log i got this message
[18-07-21 05:33:29:719 PDT] [名称空间:前缀"映射到URI" http://www.w3.org/2005/Atom ]
请帮助我解决此错误...!
Please help me to fix this error...!
谢谢.
推荐答案
我认为错误的原因是,从https://www.reddit.com/r/DigitalMarketing.rss?limit=10&after=0
检索到的content
中不包含var toText = '</div>';
的</div>
.那修改呢?
I think that the reason of the error is that </div>
of var toText = '</div>';
is not included in content
retrieved from https://www.reddit.com/r/DigitalMarketing.rss?limit=10&after=0
. So how about this modification?
-
</div>
.因此,在此修改中,我使用了</content>
.因为您将'<content type="html"><!-- SC_OFF --><div class="md"><p>'
用于fromText
. -
setValues()
而不是appendRow()
用于放置值.</div>
ofvar toText = '</div>';
is not included incontent
. So in this modification, I used</content>
. Because you are using'<content type="html"><!-- SC_OFF --><div class="md"><p>'
forfromText
.setValues()
instead ofappendRow()
is used for putting the values.- You can see the difference of the cost between
setValues()
andappendRow()
at here.
请从以下位置修改
var toText = '</div>';
到 :
var toText = '</content>';
2.对于
SAVE_DATA()
请进行如下修改.
2. For
SAVE_DATA()
Please modify as follows.
function SAVE_DATA() { var sheet = SpreadsheetApp.openById('1No3m_FnhyxIaxj2zSlbHrg8HLBJULGQ2bda65hpKlyY').getSheetByName('sample'); var content = getNewContent(); var title = getNewTitle(); var link = getNewLink(); var values = title.map(function(e, i){return [e, link[i], content[i]]}); sheet.getRange(sheet.getLastRow() + 1, 1, values.length, values[0].length).setValues(values); }
注意:
- 在此修改中,我将
var toText = '</content>';
用于getNewContent()
.如果要检索网站的其他范围,请对此进行修改. - 关于URL,已设置标题的
limit=100
.但是为链接和内容设置了limit=10
.因此,当检索值并将其放入电子表格时,链接和内容在11行中变得不确定.- 如果您已经知道这一点,请忽略它.
- In this modification, I used
var toText = '</content>';
forgetNewContent()
. If you want to retrieve other range of the site, please modify this. - About the URL,
limit=100
for the title is set. Butlimit=10
is set for the link and content. So when the values are retrieved and put them to Spreadsheet, link and content become undefined from 11 row.- If you have already known this, please ignore this.
- 使用Google Apps脚本轻松抓取数据5分钟之内
- 解析器是GAS库.您可以在这里查看.
如果我误解了你的问题,对不起.
If I misunderstand your question, I'm sorry.
这篇关于google app脚本超出内存限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
Note :
- You can see the difference of the cost between
content
中不包含var toText = '</div>';
中的