我被要求在 RSS feed 上实施一些谷歌跟踪。目前,我们跟踪用户何时单击 RSS 链接,但他们似乎也想跟踪对该链接之外的 RSS 提要的访问。
我可以暗示这个服务器端,但我只是想知道将谷歌跟踪代码(Javascript)放入RSS(XML)文件中是否实际上会被浏览器在运行时解析。
如何从 RSS 提要中获取每个项目标签内所有内容的字符串?
输入示例(简化):
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>Test</title>
<item>
<title>Hello world1</title>
<comments>Hi there</comments>
<pubDate>Tue, 21 Nov 2011 20:10:10 +0000</pubDate>
</item>
<item>
<title>Hello world2</title>
<comments>Good afternoon</comments>
<pubDate>Tue, 22 Nov 2011 20:10:10 +0000</pubDate>
</item>
<item>
<title>Hello world3</title>
<comments>blue paint</comments>
<pubDate>Tue, 23 Nov 2011 20:10:10 +0000</pubDate>
</item>
</channel>
</rss>
Run Code Online (Sandbox Code Playgroud)
我需要一个 python 函数来获取这个 RSS 文件(我现在使用 beautifulsoup),并且有一个遍历每个项目的循环。我需要一个变量,其中包含每个项目中所有内容的字符串。
第一个循环结果示例:
<title>Hello world1</title>
<comments>Hi there</comments>
<pubDate>Tue, 21 Nov 2011 20:10:10 +0000</pubDate>
Run Code Online (Sandbox Code Playgroud)
这段代码给了我第一个结果,但是我如何获得接下来的所有结果呢?
html_data = BeautifulSoup(xml)
print html_data.channel.item
Run Code Online (Sandbox Code Playgroud) 我正在编写一个对性能非常关键的程序。我正在轮询一个通常有大约 50 个条目的 Atom feed。我需要解析它才能尽快获得 uri 链接。
目前我正在这样做:
var feedUrl = "my path";
using (var feedReader = XmlReader.Create(feedUrl))
{
var feedContent = SyndicationFeed.Load(feedReader);
if (null == feedContent) return null;
foreach (var item in feedContent.Items.Reverse())
{
if (item.Title.Text.Contains("Some text I am looking for"))
{
foreach (var link in item.Links)
{
uri = link.Uri;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我从许多来源了解到,使用 for 循环比使用 foreach 快得多,因此我尝试实现这一点,但不断收到一些错误,指出无法将索引应用于 SyndicateItem。这似乎是因为 SyndicateItem 是 IEnumerable。
因此,这给我留下了两个问题:1.)是否有更好、更高效/更快的方法来做到这一点2.)我目前是否正在实施最佳解决方案?
我正在使用 Java 的罗马库来解析一些 RSS。默认情况下,它需要 25 个条目。
请告诉我,如何获得接下来的 25 个条目?
我的测试代码是:
public static SyndFeed getSyndFeedForUrl(String url) throws Exception {
SyndFeed feed = null;
InputStream is = null;
try {
URLConnection openConnection = new URL(url).openConnection();
is = new URL(url).openConnection().getInputStream();
if("gzip".equals(openConnection.getContentEncoding())){
is = new GZIPInputStream(is);
}
InputSource source = new InputSource(is);
SyndFeedInput input = new SyndFeedInput();
feed = input.build(source);
} catch (Exception e){
e.printStackTrace();
} finally {
if( is != null) is.close();
}
return feed;
}
public static void main(String[] args) {
SyndFeed …Run Code Online (Sandbox Code Playgroud) 我正在尝试从其他站点获取 RSS。file_get_contents除了一个链接给我这个错误之外,它们都可以正常工作:
警告:file_get_contents( http://alwatan.kuwait.tt/rss.ashx ):无法打开流:HTTP 请求失败!HTTP/1.1 463
我下载了所有文件,并且都有:
<rss version="2.0">
Run Code Online (Sandbox Code Playgroud)
但有错误的链接有:
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
Run Code Online (Sandbox Code Playgroud)
这是他们之间唯一的区别。
我正在使用 appstudio 代码,当我从 WordPress 获取帖子时,我可以查看图片和文本,一切都很好,但是当我尝试播放 youtube 视频时,它是打开的 Microsoft Edge 向我显示视频 谁能帮助我 这是 Html块代码
<was_controls:HtmlBlock
Grid.Row="2"
FlowDirection="RightToLeft"
Margin="24,10,24,130"
Style="{StaticResource HtmlPersonalStyle}"
FontSize="{Binding ViewModel.FontSize, ElementName=root}"
Source="{Binding ViewModel.SelectedItem.Description}" Grid.RowSpan="2"/>
Run Code Online (Sandbox Code Playgroud)
和 Html 样式:
<Style TargetType="was:HtmlBlock" x:Key="HtmlPersonalStyle">
<Setter Property="Foreground" Value="{ThemeResource ApplicationHeaderForegroundThemeBrush}"/>
<Setter Property="DocumentStyle">
<Setter.Value>
<was:DocumentStyle>
<was:DocumentStyle.Channel9>
<was:ImageStyle HorizontalAlignment="Center"/>
</was:DocumentStyle.Channel9>
<was:DocumentStyle.Img>
<was:ImageStyle HorizontalAlignment="Center"/>
</was:DocumentStyle.Img>
<was:DocumentStyle.P>
<was:ParagraphStyle Margin="0,24,0,24" />
</was:DocumentStyle.P>
<was:DocumentStyle.Code>
<was:TextStyle Foreground="{StaticResource NavigationPaneButton}" FontWeight="Bold" />
</was:DocumentStyle.Code>
<was:DocumentStyle.FigCaption>
<was:ParagraphStyle Foreground="SaddleBrown"/>
</was:DocumentStyle.FigCaption>
<was:DocumentStyle.Ul>
<was:ContainerStyle Margin="0,24,0,24" />
</was:DocumentStyle.Ul>
<was:DocumentStyle.H1>
<was:ParagraphStyle FontSizeRatio="2" />
</was:DocumentStyle.H1>
<was:DocumentStyle.H2>
<was:ParagraphStyle />
</was:DocumentStyle.H2>
<was:DocumentStyle.Li>
<was:ListStyle FontWeight="Bold" …Run Code Online (Sandbox Code Playgroud) 我正在尝试处理 RSS 提要,但想反向执行,以便最后导入最新项目以保持顺序正确。
$content = file_get_contents($feed_url);
$rss = new SimpleXmlElement($content);
$rss = array_reverse($rss);
foreach($rss->channel->item as $entry) {
echo $entry->title;
}
Run Code Online (Sandbox Code Playgroud)
然而上面只是抛出array_reverse() expects parameter 1 to be array&Invalid argument supplied for foreach()错误。我怎样才能反转数组,以便 for each 向后工作?
这是我第一次使用反应。我从 jQuery 到 React 这感觉就像一个很大的飞跃。如果有人能帮我重构它以按照 React 的方式工作,我将永远欠你的债!:)
我正在尝试解析 RSS 提要,我想在其中获取最新的帖子标题和链接以呈现到组件中。
https://www.npmjs.com/package/rss-parser - 使用它来获取解析器。
在浏览器中查看我的应用程序时,异步函数将 rss 提要吐出到控制台,我想这是一个好的开始!
// src/App/index.tsx
import * as React from 'react';
import * as Parser from 'rss-parser';
// Types
import { string } from 'prop-types';
let parser = new Parser();
// blueprint for the properties
interface Props {
name: string;
}
// Component state
interface State {
//feed: any[];
}
(async () => {
let feed = await parser.parseURL('https://www.reddit.com/.rss');
console.log(feed.title);
feed.items.forEach((item: { title: string; link: string; }) …Run Code Online (Sandbox Code Playgroud) 有这个模型:
class MyModel(models.Model):
…
image = StdImageField(
upload_to="img/images",
blank=True,
variations={
"large": (1024, 1024),
"thumbnail": (150, 150, False),
"medium": (600, 600),
},
delete_orphans=True,
)
Run Code Online (Sandbox Code Playgroud)
而这个观点
…
from django.contrib.syndication.views import Feed
…
class LatestItems(Feed):
title = "LatestItems"
description = "Latest Items"
link = "/sitenews/"
def items(self):
return MyModel.objects.all()
def item_title(self, item):
return item.description_short
def item_description(self, item):
return item.description
def item_link(self, item):
return reverse('item_detail', args=[item.pk])
Run Code Online (Sandbox Code Playgroud)
如何将图像添加到 RSS 文章的正文中?
我正在尝试从SharePoint列表中仅获取某些项目.RSS提要给了我一切,即使我已经过滤了查看特定视图的列表.