May be this question already asked, but that won't solve my problem.
I try to save data's into google spreadsheet
using google app script
. But it shows Exceeded memory limit error.
following my code:
//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
In my above code am tried to save the data from url
.
But i get
Exceeded memory limit
error.
In my Log i got this message
[18-07-21 05:33:29:719 PDT] [Namespace: prefix "" is mapped to URI "http://www.w3.org/2005/Atom"]
Please help me to fix this error...!
Thanks in advance.
I think that the reason of the error is that
</div>
ofvar toText = '</div>';
is not included incontent
retrieved fromhttps://www.reddit.com/r/DigitalMarketing.rss?limit=10&after=0
. So how about this modification?Modification points :
</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.setValues()
andappendRow()
at here.Modified script :
1. For
getNewContent()
Please modify from
From : To :2. For
SAVE_DATA()
Please modify as follows.
Note :
var toText = '</content>';
forgetNewContent()
. If you want to retrieve other range of the site, please modify this.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.Reference :
If I misunderstand your question, I'm sorry.