gpt4 book ai didi

javascript - Google 脚本 XML 解析

转载 作者:行者123 更新时间:2023-12-02 13:52:45 25 4
gpt4 key购买 nike

我正在解析以下 XML:

<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xml:base="https://www.sportsbook.ag/rss/nfl-football" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Sportsbook.com Live Football Betting Odds RSS Feed</title>
<link>https://www.sportsbook.ag/rss/nfl-football</link>
<description>Football Betting Feed</description>
<language>en</language>
<item>
<title>Dallas Cowboys @ Minnesota Vikings</title>
<link>http://www.sportsbook.ag/livesports/nfl</link>
<description>&lt;strong&gt;12-1-16 8:25 PM&lt;/strong&gt;
Bet on Dallas Cowboys &lt;a href=&quot;https://www.sportsbook.ag/sbk/sportsbook4/www.sportsbook.ag/updatecart5.cgi?sportTypeId=203&amp;amp;action=addBet&amp;amp;betTypeId=80&amp;amp;selection[Foot-Dalla-Minne-120116PSA]=Foot-Dalla-Minne-120116|PSA|1|100|115|-7|-115&quot;&gt;-3.5 (-115)&lt;/a&gt;
Money:&lt;a href=&quot;https://www.sportsbook.ag/sbk/sportsbook4/www.sportsbook.ag/updatecart5.cgi?sportTypeId=203&amp;amp;action=addBet&amp;amp;betTypeId=80&amp;amp;selection[Foot-Dalla-Minne-120116MLA]=Foot-Dalla-Minne-120116|MLA|1|100|180|0|-180&quot;&gt;-180&lt;/a&gt;
or Minnesota Vikings &lt;a href=&quot;https://www.sportsbook.ag/sbk/sportsbook4/www.sportsbook.ag/updatecart5.cgi?sportTypeId=203&amp;amp;action=addBet&amp;amp;betTypeId=80&amp;amp;/selection[Foot-Dalla-Minne-120116PSH]=Foot-Dalla-Minne-120116|PSH|1|100|105|7|-105&quot;&gt;3.5 (-105)&lt;/a&gt;
Money:&lt;a href=&quot;https://www.sportsbook.ag/sbk/sportsbook4/www.sportsbook.ag/updatecart5.cgi?sportTypeId=203&amp;amp;action=addBet&amp;amp;betTypeId=80&amp;amp;selection[Foot-Dalla-Minne-120116MLA]=Foot-Dalla-Minne-120116|MLA|1|100|180|0|-180&quot;&gt;+157&lt;/a&gt;.
Totals: &lt;a href=&quot;https://www.sportsbook.ag/sbk/sportsbook4/www.sportsbook.ag/updatecart5.cgi?sportTypeId=203&amp;amp;action=addBet&amp;amp;betTypeId=80&amp;amp;selection[Foot-Dalla-Minne-120116TLO]=Foot-Dalla-Minne-120116|TLO|1|100|110|89|-110&quot;&gt;Over 44.5 (-110)&lt;/a&gt;
&lt;a href=&quot;https://www.sportsbook.ag/sbk/sportsbook4/www.sportsbook.ag/updatecart5.cgi?sportTypeId=203&amp;amp;action=addBet&amp;amp;betTypeId=80&amp;amp;selection[Foot-Dalla-Minne-120116TLU]=Foot-Dalla-Minne-120116|TLU|1|100|110|89|-110&quot;&gt;Under 44.5 (-110)&lt;/a&gt;</description>
<pubDate>12-1-16 8:25 PM</pubDate>
<dc:creator />
<guid isPermaLink="false" />
</item>

使用以下 Google Apps 脚本:

function stugass() {
var live = new Array();
var url = "https://www.sportsbook.ag/rss/nfl-football";
var parameters = {method : "get", payload : ""};
var xml = UrlFetchApp.fetch(url, parameters).getContentText();
var document = XmlService.parse(xml);
var games = document.getRootElement().getChild('channel').getChildren('item');
if(document == null) {
document.getRootElement().getChild('channel').getChildren('item');
}
for (var i=0; i < games.length-1; i++) {
vegas = [];
var game = games[i];
vegas.push(game.getChildText('title'));
vegas.push(game.getChildText('link'));
vegas.push(game.getChildText('description'));


live.push(vegas);
}
return live;
}

如何将“描述”标记的“BLOB”部分拆分到 Google 电子表格中的多个单元格中?

最佳答案

您想要将该字段拆分到多远并不明显,但这是一种方法,使用带有正则表达式参数的 split 字符串方法,该方法按该描述中找到的 HTML 标签进行拆分。此方法返回的数组经过过滤以消除任何仅包含空格的部分。

var description = game.getChildText('description').split(/<\/?strong>|<a href="|">[^<]*<\/a>/);
vegas = vegas.concat(description.filter(function (a) {return a.trim().length;}));
live.push(vegas);

输出看起来像

12-1-16 8:25 PM  |   Bet on Dallas Cowboys   |  https://www.sportsbook.ag/sbk/sportsbook4/www.sportsbook.ag/updatecart5.cgi?sportTypeId=203&amp;action=addBet&amp;betTypeId=80&amp;selection[Foot-Dalla-Minne-120116PSA]=Foot-Dalla-Minne-120116|PSA|1|100|105|-7|-105   |  ... 

关于javascript - Google 脚本 XML 解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40921605/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com