Home > Net >  How to get prototype data from rss . file?
How to get prototype data from rss . file?

Time:10-05

I have 1 rss file and I want to get the data including the html code from here. I tried with IMPORTFEED from Sheet but it doesn't display the html code as I want.

Here is my sample rss file:

 <channel>
<item>
<title>5 Small Business Digital Marketing Tips | Donklephant</title>
<link>https://www.google.com/url?rct=j&sa=t&url=https://donklephant.com/5-small-business-digital-marketing-tips/&ct=ga&cd=CAIyGjRkOWNlYjEwZThmZWEzYzk6Y29tOmVuOlVT&usg=AFQjCNG2rQuRDUiY_UppXg7LAt5uw1ZDXQ</link>
<dc:identifier/>
<pubDate>Sun, 03 Oct 2021 07:26:15  0000</pubDate>
<dc:creator/>
<guid isPermaLink="true">https://www.google.com/url?rct=j&amp;sa=t&amp;url=https://donklephant.com/5-small-business-digital-marketing-tips/&amp;ct=ga&amp;cd=CAIyGjRkOWNlYjEwZThmZWEzYzk6Y29tOmVuOlVT&amp;usg=AFQjCNG2rQuRDUiY_UppXg7LAt5uw1ZDXQ</guid>
<description>Getting leads and sales is sometimes more difficult than business owners expect. In fact, about 65% of businesses say it’s their biggest marketing challenge. With a strong digital marketing strategy, however, you don’t have to struggle.  Here are five digital marketing tips that can set your...</description>
<content:encoded><div><img src="https://donklephant.com/wp-content/uploads/2021/10/01425af1e662eeeada815f0cad2f9746.jpeg" class="ff-og-image-inserted"></div><p>Getting leads and sales is sometimes more difficult than business owners expect. In fact, about <a href="https://www.smallbizgenius.net/by-the-numbers/lead-nurturing-statistics/#gref">65% of businesses</a> say it’s their biggest marketing challenge. With a strong digital marketing strategy, however, you don’t have to struggle. </p> <p>Here are five digital marketing tips that can set your business up for growth and lasting success. With this digital marketing advice, you can get ahead of the competition. You can retain repeat customers to improve your ROI, too.</p> <p>Set your business up for growth this year. Develop your digital marketing plan with these five tips today. </p> <h2><span>1. Establish Brand Guidelines</span></h2> <p>A distinct brand will help your business stand out from the competition. Otherwise, consumers might not even realize you exist. Take the time to establish brand guidelines before developing your digital marketing plan.</p> <p>Your guidelines should outline your:</p> <ul> <li>Mission statement</li> <li>Vision statement</li> <li>Personality</li> <li>Voice</li> <li>Tone</li> <li>Color palette</li> <li>Photography/imagery styles</li> <li>Logo styles</li> <li>Font styles</li> </ul> <p>Make sure to maintain brand consistency as you use the rest of this digital marketing advice. Consistency will help awareness grow into recognition. People will start recognizing your materials through your visual brand. </p> <h2><span>2. Update Your Website</span></h2> <p>Take the time to update your website as well. An old, slow, outdated website could cost you customers.</p> <p>In fact, <a href="https://fitsmallbusiness.com/website-statistics/">38% of consumers</a> stop interacting with poorly designed websites. They might judge your credibility based on your site, too.</p> <p>Instead, update your website by following the latest user experience design trends. Make sure your site is fast and mobile-ready, too. </p> <p>You can learn how to get the most from your <a href="https://stephenholmes.co.uk/how-to-get-the-most-from-your-web-design/">web design</a> here.</p> <h2><span>3. Create Content</span></h2> <p>Once you update your website, add content creation to your digital marketing strategy. Then, optimize your content for search engine optimization (SEO).</p> <p>SEO will help people find your website when they search for your product or service online.</p> <h2><span>4. Gather and Nurture Leads</span></h2> <p>As you use these digital marketing tips, make sure you have a plan for generating leads.</p> <p>For example, you can add a form to your website. Consider using a chatbot or lead magnets as well.</p> <p>Once you start gathering leads, use business marketing strategies like email marketing to nurture them. Email marketing will help you remain top of mind. </p> <h2><span>5. Stay Social</span></h2> <p>Don’t neglect social media! Adding social media to your digital marketing plan will help you engage your target audience.</p> <p>Reformat your blog posts for social media. Once people comment on your posts, respond! Create two-way conversations and engage your customer.</p> <p>Otherwise, use influencer marketing to expand your reach online. </p> <p>Keep up-to-date with the latest trends, too. For example, video content is becoming more popular. AR and VR are gaining popularity, too.</p> <p>Keeping up with the trends will show consumers you’re relevant. </p> <h2><span>Get Growing: 5 Digital Marketing Tips for Your Small Business</span></h2> <p>Don’t let your digital marketing strategy grow stale. Instead, use these digital marketing tips to expand your reach online. With these tips, you can market your services and boost brand awareness.</p> <p>Start generating more leads and sales with these business marketing tips today.</p> <p>Hunting for more tips? You’ve come to the right place.</p> <p>Check out our latest guides for more useful advice. </p></content:encoded>
</item>
</channel>

And I want to get the data in content:encoded including the html tags:

<img src="https://donklephant.com/wp-content/uploads/2021/10/01425af1e662eeeada815f0cad2f9746.jpeg" class="ff-og-image-inserted"></div><p>Getting leads and sales is sometimes more difficult than business owners expect. In fact, about <a href="https://www.smallbizgenius.net/by-the-numbers/lead-nurturing-statistics/#gref">65% of businesses</a> say it’s their biggest marketing challenge. With a strong digital marketing strategy, however, you don’t have to struggle. </p> <p>Here are five digital marketing tips that can set your business up for growth and lasting success. With this digital marketing advice, you can get ahead of the competition. You can retain repeat customers to improve your ROI, too.</p> <p>Set your business up for growth this year. Develop your digital marketing plan with these five tips today. </p> <h2><span>1. Establish Brand Guidelines</span></h2> <p>A distinct brand will help your business stand out from the competition. Otherwise, consumers might not even realize you exist. Take the time to establish brand guidelines before developing your digital marketing plan.</p> <p>Your guidelines should outline your:</p> <ul> <li>Mission statement</li> <li>Vision statement</li> <li>Personality</li> <li>Voice</li> <li>Tone</li> <li>Color palette</li> <li>Photography/imagery styles</li> <li>Logo styles</li> <li>Font styles</li> </ul> <p>Make sure to maintain brand consistency as you use the rest of this digital marketing advice. Consistency will help awareness grow into recognition. People will start recognizing your materials through your visual brand. </p> <h2><span>2. Update Your Website</span></h2> <p>Take the time to update your website as well. An old, slow, outdated website could cost you customers.</p> <p>In fact, <a href="https://fitsmallbusiness.com/website-statistics/">38% of consumers</a> stop interacting with poorly designed websites. They might judge your credibility based on your site, too.</p> <p>Instead, update your website by following the latest user experience design trends. Make sure your site is fast and mobile-ready, too. </p> <p>You can learn how to get the most from your <a href="https://stephenholmes.co.uk/how-to-get-the-most-from-your-web-design/">web design</a> here.</p> <h2><span>3. Create Content</span></h2> <p>Once you update your website, add content creation to your digital marketing strategy. Then, optimize your content for search engine optimization (SEO).</p> <p>SEO will help people find your website when they search for your product or service online.</p> <h2><span>4. Gather and Nurture Leads</span></h2> <p>As you use these digital marketing tips, make sure you have a plan for generating leads.</p> <p>For example, you can add a form to your website. Consider using a chatbot or lead magnets as well.</p> <p>Once you start gathering leads, use business marketing strategies like email marketing to nurture them. Email marketing will help you remain top of mind. </p> <h2><span>5. Stay Social</span></h2> <p>Don’t neglect social media! Adding social media to your digital marketing plan will help you engage your target audience.</p> <p>Reformat your blog posts for social media. Once people comment on your posts, respond! Create two-way conversations and engage your customer.</p> <p>Otherwise, use influencer marketing to expand your reach online. </p> <p>Keep up-to-date with the latest trends, too. For example, video content is becoming more popular. AR and VR are gaining popularity, too.</p> <p>Keeping up with the trends will show consumers you’re relevant. </p> <h2><span>Get Growing: 5 Digital Marketing Tips for Your Small Business</span></h2> <p>Don’t let your digital marketing strategy grow stale. Instead, use these digital marketing tips to expand your reach online. With these tips, you can market your services and boost brand awareness.</p> <p>Start generating more leads and sales with these business marketing tips today.</p> <p>Hunting for more tips? You’ve come to the right place.</p> <p>Check out our latest guides for more useful advice. </p>

Please help me!

Update: @Tanaike Below is my RSS URL. It has many items.

https://cdn.feedcontrol.net/1830/2857-8L5Ntr0N5l5Xf.xml

My real intent is to get the <title> and <content:encoded> of each item to create a Google Docs file. And I want that Docs file to keep its structure.

So I tried with your help but it doesn't work as I wanted.

 function myFunction() {
    const url = "https://cdn.feedcontrol.net/1830/2857-8L5Ntr0N5l5Xf.xml"; // Please set URL.

    const data = UrlFetchApp.fetch(url).getContentText();
    const res = data.match(/<content:encoded>([\s\S\w] )<\/content:encoded>/);
    Logger.log(res)
    if (res) {
      var blob1 = Utilities.newBlob("").setDataFromString(res[1], "UTF-8").setContentType("text/html");
      Drive.Files.insert({title: "TEST"}, blob1, {convert: true});
      //DriveApp.createFile("sample.html", res[1], MimeType.HTML);
    }
  }

Looking forward to your help.

CodePudding user response:

I believe your goal as follows.

  • You have a file on Google Drive.
  • You want to retrieve the value of ### of <content:encoded>###</content:encoded> using Google Apps Script.

When I tested your data, unfortunately, the data couldn't be parsed by XmlService because of a parsed error. So in this answer, I used the regex for retrieving the value you need. The sample script is as follows.

Sample script:

function myFunction() {
  const fileId = "###"; // Please set the file ID of the file including the data.

  const data = DriveApp.getFileById(fileId).getBlob().getDataAsString();
  const res = data.match(/<content:encoded>([\s\S\w] )<\/content:encoded>/);
  if (res) {
    DriveApp.createFile("sample.html", res[1], MimeType.HTML);
  }
}
  • When this script is run, the file including the data is opened and retrieved the data, and the value of ### of <content:encoded>###</content:encoded> is retrieved. And then, the retrieved data is outputted as a HTML file to the root folder.

  • If your data is required to be retrieved from the web site, please modify data as follows.

      function myFunction() {
        const url = "###"; // Please set URL.
    
        const data = UrlFetchApp.fetch(url).getContentText();
        const res = data.match(/<content:encoded>([\s\S\w] )<\/content:encoded>/);
        if (res) {
          DriveApp.createFile("sample.html", res[1], MimeType.HTML);
        }
      }
    

References:

Edit:

From your updated question and your following comment,

My real intent is to get the and content:encoded of each item to create a Google Docs file. And I want that Docs file to keep its structure.

I want to generate google Docs from that RSS. For example with the first item, I want to create a Docs file with the name of the item. And the Docs file has the content:encoded content of the item. This is the output Docs file that I want: https://docs.google.com/document/d/1DjPmBSZWoKcvJpuBssQ_3YtxwQrV2eg4QO6VUZqxMsQ/edit?usp=sharing. Hope you understand because my English is translated from google translate.

I understood that your initial question was different from your actual question. In this case, I think that the HTML can be converted to Google Document, the output result might be different from your goal because of the current specification of the Google side. So please test the following sample script.

Sample script 1:

In this script, Google Document is created to the root folder by the values of <title> and <content:encoded>. But, I thought that the output Google Document converted from the HTML data might not be the same result as your goal.

function myFunction1() {
  const url = "https://cdn.feedcontrol.net/1830/2857-8L5Ntr0N5l5Xf.xml";
  const data = UrlFetchApp.fetch(url).getContentText();
  const root = XmlService.parse(data).getRootElement();
  const ns1 = root.getNamespace();
  const ns2 = XmlService.getNamespace("http://purl.org/rss/1.0/modules/content/");
  root.getChild("channel", ns1).getChildren("item", ns1).forEach(e => {
    Drive.Files.insert({title: e.getChild("title", ns1).getValue(), mimeType: MimeType.GOOGLE_DOCS}, HtmlService.createHtmlOutput(e.getChild("encoded", ns2).getValue()).getBlob());
  });
}

Sample script 2:

In this script, the PDF file is created to the root folder by the values of <title> and <content:encoded>. I thought that the output PDF file converted from the HTML data might be the same result as your goal. But, the mimeType is not Google Document.

function myFunction2() {
  const url = "https://cdn.feedcontrol.net/1830/2857-8L5Ntr0N5l5Xf.xml";
  const data = UrlFetchApp.fetch(url).getContentText();
  const root = XmlService.parse(data).getRootElement();
  const ns1 = root.getNamespace();
  const ns2 = XmlService.getNamespace("http://purl.org/rss/1.0/modules/content/");
  root.getChild("channel", ns1).getChildren("item", ns1).forEach(e => {
    let html = e.getChild("encoded", ns2).getValue();
    const url = html.match(/<img src\=\"([\s\S\w] ?)\"/);
    if (url) {
      const blob = UrlFetchApp.fetch(url[1].replace(/&amp;/g, "&").trim()).getBlob();
      const base64 = blob.getContentType()   ';base64,'  Utilities.base64Encode(blob.getBytes());
      html = html.replace(/<img src\=\"[\s\S\w] ?>/, `<img src="data:${base64}">`);
    }
    DriveApp.createFile(HtmlService.createHtmlOutput(html).getAs(MimeType.PDF).setName(e.getChild("title", ns1).getValue()));
  });
}
  • Related