标签: feedparser

在Django模板标记库中导入外部库时出错

所以我正在尝试编写一个Django可重用的应用程序,它提供了一种在页面上显示Twitter提要的方法.我知道它已经存在了20次.这是一次学术练习.:)

目录结构非常简单:

myproject
|__  __init__.py
|__  manage.py
|__  settings.py
|__  myapp
     |__  __init__.py
     |__  admin.py
     |__  conf
          |__  __init__.py
          |__  appsettings.py
     |__  feedparser.py
     |__  models.py
     |__  templates
          |__  __init__.py
     |__  templatetags
          |__  __init__.py
          |__  twitterfeed.py
     |__  views.py
|__  templates
          |__  base.html
|__  urls.py
Run Code Online (Sandbox Code Playgroud)

运行Django shell时,twitterfeed.py中定义的函数完美运行.我也相信我有正确命名和注册的模板标签.

如您所见,我使用了优秀的Universal Feed Parser.我的问题不在UFP本身,而是UFP在导入模板标签库时无法调用.当我{% load twitterfeed %}在base.py时,我收到以下错误:

'twitterfeed'不是有效的标记库:无法从django.templatetags.twitterfeed加载模板库,没有名为feedparser的模块

我使用以下语句导入feedparser:

import re, datetime, time, myapp.feedparser
Run Code Online (Sandbox Code Playgroud)

我能说的最好,这个错误信息有点欺骗.我认为加载模板库时会发生ImportError,这是Django对它的解释.

有没有什么办法可以在我的可重用应用程序中导入feedparser.py,而无需让应用程序的用户在其PythonPath中的某处放置feedparser?

谢谢!

python django feedparser templatetags

3
推荐指数
1
解决办法
4215
查看次数

使用feedparser按日期限制RSS元素.[蟒蛇]

我迭代一个RSS提要,因为_file是feed

d = feedparser.parse(_file)
for element in d.entries: 
    print repr(element.date)
Run Code Online (Sandbox Code Playgroud)

日期输出就像这样

u'Thu, 16 Jul 2009 15:18:22 EDT'
Run Code Online (Sandbox Code Playgroud)

我似乎无法理解如何实际量化上述日期输出,所以我可以用它来限制饲料元素.我所以我要问的是如何才能获得实际的时间,所以我可以说如果超过7天,请跳过这个元素.

python feedparser

3
推荐指数
1
解决办法
1017
查看次数

如何同时获取多个提要

我是ruby on rails的新手,我刚刚开始观看rails casts教程.

为了解析feed,我已经开始使用feed zirra了.

要一次获取多个Feed,feedzirra具有此功能

feed_urls = ["http://feeds.feedburner.com/PaulDixExplainsNothing",
"http://feeds.feedburner.com/trottercashion"]
feeds = Feedzirra::Feed.fetch_and_parse(feed_urls)
Run Code Online (Sandbox Code Playgroud)

如果我有100个Feed,此过程需要一些时间来索引第100个Feed,因此,

如何解析所有这些让我们同时说100个提要?

期待您的帮助和支持

concurrency parsing ruby-on-rails feedparser feedzirra

3
推荐指数
1
解决办法
766
查看次数

从FeedParser获取Feed并导入到Pandas DataFrame

我正在学习python.作为练习我正在使用feedparser构建一个rss scraper,将输出放入pandas数据框并尝试使用NLTK ...但我首先从多个RSS提要中获取文章列表.

我使用这篇文章介绍了如何传递多个feed,并将其与我之前收到的关于如何将其变为Pandas数据帧的另一个问题的答案相结合.

问题是,我希望能够查看数据框中所有Feed的数据.目前,我只能访问供稿列表中的第一项.

FeedParser似乎正在做它的工作但是当把它放入Pandas df时它似乎只抓住了列表中的第一个RSS.

import feedparser
import pandas as pd

rawrss = [
    'http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml',
    'https://www.yahoo.com/news/rss/',
    'http://www.huffingtonpost.co.uk/feeds/index.xml',
    'http://feeds.feedburner.com/TechCrunch/',
    ]

feeds = []
for url in rawrss:
    feeds.append(feedparser.parse(url))

for feed in feeds:
    for post in feed.entries:
        print(post.title, post.link, post.summary)

df = pd.DataFrame(columns=['title', 'link', 'summary'])

for i, post in enumerate(feed.entries):
    df.loc[i] =  post.title, post.link, post.summary

df.shape

df
Run Code Online (Sandbox Code Playgroud)

python feedparser pandas

3
推荐指数
1
解决办法
1492
查看次数

如何检测页面是RSS还是ATOM源

我目前正在用PHP构建一个新的在线Feed阅读器.我正在研究的功能之一是Feed自动发现.如果用户输入网站URL,脚本将检测到它不是Feed,并通过解析HTML以获取正确的标记来查找实际的Feed URL.

问题是,我目前正在检测URL是Feed还是网站的方式只能部分工作,我知道它不是最好的解决方案.现在我正在接受CURL响应并通过simplexml_load_string运行它,如果它无法解析它我将其视为一个网站.这是代码.

$xml = @simplexml_load_string( $site_found['content'] );

if( !$xml ) // this is a website, not a feed
{
    // handle website
}
else
{
    // parse feed
}
Run Code Online (Sandbox Code Playgroud)

显然,这并不理想.此外,当它运行到可以解析的HTML网站时,它会认为它是一个提要.

有关检测PHP中的feed或non-feed之间差异的好方法的任何建议?

谢谢,

辣椒 http://feedingo.com

php rss feedparser atom-feed

2
推荐指数
1
解决办法
6243
查看次数

如何使Universal Feed Parser仅解析Feed?

我正在尝试使用Universal Feed Parser从我的Django网站上获取外部源的内容.我希望有一些用户错误处理,例如,如果用户提供的URL不是Feed.当我尝试feedparser如何响应错误的输入时,我惊讶地发现feedparser根本没有抛出任何异常.例如,在HTML内容上,它尝试从HTML代码中解析一些信息,在非现有域上,它返回一个基本上为空的字典:

{'bozo': 1,
'bozo_exception': URLError(gaierror(-2, 'Name or service not known'),),
'encoding': 'utf-8',
'entries': [],
'feed': {},
'version': None}
Run Code Online (Sandbox Code Playgroud)

其他错误输入在返回的字典中status_codenamespaces值或值中显示.

那么,如何在不诉诸无尽级联的情况下进行合理的错误检查的最佳方法是if .. elif .. elif ...什么?

python feedparser

2
推荐指数
1
解决办法
2163
查看次数

带有RSS pubDate的NSDateFormatter

将rss pubdate字符串转换为NSDate对象时遇到一些问题.

<pubDate>Fri, 09 Sep 2011 15:26:08 +0200</pubDate>

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EEE, d MMM yyyy HH:mm:ss Z"];
NSDate *date = [dateFormatter dateFromString:currentDate];
NSLog(@"DateObject : '%@'", date);
[dateFormatter release];
Run Code Online (Sandbox Code Playgroud)

我总是得到

 [44157:10d03] DateObject : '(null)'
Run Code Online (Sandbox Code Playgroud)

objective-c feedparser

2
推荐指数
1
解决办法
2569
查看次数

将feedparser与Google App Engine配合使用

我正在尝试使用feedparser解析RSS提要.为简洁起见,下面的代码剪短了

from google.appengine.api import urlfetch
import feedparser
print 'Content-Type: text/plain'

feed_url = 'http://parsethisurl'
feedinput = urlfetch.fetch(feed_url)

rss_parsed = feedparser.parse(feedinput.content)
......
#some logic here
.........

print "\n".join(episode_info) # printing out the desired output.
Run Code Online (Sandbox Code Playgroud)

我的python解释器工作正常,但当我将我的应用程序添加到gapp引擎启动器并尝试通过localhost:10000它运行它给我以下错误

<type 'exceptions.ImportError'>: No module named feedparser 
      args = ('No module named feedparser',) 
      message = 'No module named feedparser'
Run Code Online (Sandbox Code Playgroud)

feedparser 模块已安装在我的系统上.

>>> sys.version
'2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)]'
>>> import feedparser
>>>
Run Code Online (Sandbox Code Playgroud)

我读了一些关于stackoveflow和博客的文章,这些文章feedparser不能直接在gapp引擎上运行.我遵循了建议并使用了urlfetch.fetch(feed_url)但是我也遇到了错误.

PS:gapp启动器上的PythonPath是 C:\Python25\python.exe

python google-app-engine feedparser python-2.5

2
推荐指数
1
解决办法
1436
查看次数

阅读RSS feed并在Django Template中显示它 feedparser

请参阅此博客:http://johnsmallman.wordpress.com/author/johnsmallman/feed/

我想为我的应用程序获取RSS提要.上面的博客是一个wordpress博客.

我在用 feedparser

import feedparser
feeds = feedparser.parse('http://johnsmallman.wordpress.com/author/johnsmallman/feed/')
Run Code Online (Sandbox Code Playgroud)

现在feeds['feed']['title']输出u"Johnsmallman's Blog \xbb John Smallman"

我的问题是我在我的应用程序中如何呈现这一点.让我们说这篇博客包含了100篇文章.所以我想循环并获取所有数据.

这样做有没有直接的方法?任何预定义的库或方法?

我有谷歌用谷歌搜索但很难过.

我基本上希望将它呈现给Django Template.所以真的会对它有所了解.

需要指导的人:)

python django rss django-templates feedparser

2
推荐指数
1
解决办法
3474
查看次数

feedparser 无法获得 youtube 播放器

我正在测试feedparser我的 RSS 提要。它就像一个魅力,我得到了所有的条目。

有些新闻有一个内嵌的 youtube 播放器,但这只是没有出现在 feedparser 的返回值中。

我的代码很简单:

d = feedparser.parse('http://feeds.feedburner.com/NotciasPs3evita-Mypst')
Run Code Online (Sandbox Code Playgroud)

这将返回(摘录):

 guidislink': False,
          'id': u'http://mypst.com.br/forum/index.php?/topic/17336-gamegen-call-of-duty-black-ops-2-ganha-trailer-com-acao-real-e-muitas-surpresas/',
          'link': u'http://mypst.com.br/forum/index.php?/topic/17336-gamegen-call-of-duty-black-ops-2-ganha-trailer-com-acao-real-e-muitas-surpresas/',
          'links': [{'href': u'http://mypst.com.br/forum/index.php?/topic/17336-gamegen-call-of-duty-black-ops-2-ganha-trailer-com-acao-real-e-muitas-surpresas/',
                     'rel': u'alternate',
                     'type': u'text/html'}],
          'published': u'Mon, 29 Oct 2012 14:53:58 +0000',
          'published_parsed': time.struct_time(tm_year=2012, tm_mon=10, tm_mday=29, tm_hour=14, tm_min=53, tm_sec=58, tm_wday=0, tm_yday=303, tm_isdst=0),
          'summary': u'A Activision revelou hoje um novo trailer de Call of Duty: Black Ops 2, substituindo as cenas de a\xe7\xe3o do jogo por cenas de a\xe7\xe3o na vida real. O trailer traz diversas \u201csurpresas\u201d e …
Run Code Online (Sandbox Code Playgroud)

python feedparser

1
推荐指数
1
解决办法
412
查看次数