首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从rss中获取原型数据。档案?

如何从rss中获取原型数据。档案?
EN

Stack Overflow用户
提问于 2021-10-04 09:55:43
回答 1查看 54关注 0票数 1

我有一个rss文件,我想从这里获取数据,包括html代码。我试过使用工作表中的IMPORTFEED,但是它没有显示我想要的html代码。

下面是我的示例rss文件:

代码语言:javascript
复制
 <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>

我想获取内容中的数据:编码,包括html标记:

代码语言:javascript
复制
<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>

请帮帮我!

更新:@Tanaike下面是我的RSS URL。它有很多东西。

代码语言:javascript
复制
https://cdn.feedcontrol.net/1830/2857-8L5Ntr0N5l5Xf.xml

我的真正目的是获取每个项目的<title><content:encoded>,以创建一个Google文件。我想让Docs文件保持它的结构。

所以我在你的帮助下试过了,但不像我想的那样有效。

代码语言:javascript
复制
 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);
    }
  }

期待你的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-10-04 11:41:07

我相信你的目标如下。

  • 你在谷歌硬盘上有个文件。
  • 您希望使用Google脚本检索### of <content:encoded>###</content:encoded>的值。

当我测试您的数据时,不幸的是,由于分析的错误,XmlService无法解析这些数据。因此,在这个答案中,我使用regex来检索所需的值。示例脚本如下所示。

示例脚本:

代码语言:javascript
复制
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);
  }
}
  • 运行此脚本时,打开并检索包含数据的文件,并检索### of <content:encoded>###</content:encoded>的值。然后,将检索到的数据作为HTML文件输出到根文件夹。
  • 如果需要从网站检索数据,请按以下方式修改data。 函数myFunction() { const = "###";//请设置###。const = UrlFetchApp.fetch(url).getContentText();const =UrlFetchApp.fetch if ( res ) { DriveApp.createFile("sample.html",res1,MimeType.HTML);}

参考文献:

编辑:

根据你最新的问题和下面的评论,

我真正的目的是获取和内容:编码的每一个项目,以创建一个谷歌文档文件。我想让Docs文件保持它的结构。我想从那个RSS中生成谷歌文档。例如,对于第一项,我希望创建一个具有项目名称的Docs文件。而Docs文件具有内容:项的编码内容。这是我想要的输出文档文件:3 YtxwQrV2eg4QO6VUZqxMsQ/编辑?usp=共享。希望你能理解,因为我的英语是从谷歌翻译过来的。

我知道你最初的问题和你的实际问题不同。在这种情况下,我认为HTML可以转换为Google文档,由于Google端的当前规范,输出结果可能与您的目标不同。因此,请测试以下示例脚本。

示例脚本1:

在这个脚本中,Google是通过<title><content:encoded>的值创建到根文件夹的。但是,我认为从HTML数据转换出来的Google文档可能与你的目标不同。

代码语言:javascript
复制
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());
  });
}

示例脚本2:

在这个脚本中,PDF文件是通过<title><content:encoded>的值创建到根文件夹的。我认为从HTML数据转换而来的输出PDF文件可能与您的目标相同。但是,mimeType并不是谷歌的文档。

代码语言:javascript
复制
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()));
  });
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69434026

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档