Skip to content

Instantly share code, notes, and snippets.

@i5on9i
Last active March 10, 2016 09:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save i5on9i/43da27f6f348b52160e1 to your computer and use it in GitHub Desktop.
Save i5on9i/43da27f6f348b52160e1 to your computer and use it in GitHub Desktop.
# coding=utf-8
import re
from lxml import etree
import requests
__author__ = 'namh'
class JdnyRssParser(object):
url = 'http://pod.ssenhosting.com/rss/rrojia2/rrojia2.xml'
def __init__(self):
pass
def _getText(self, item, xpath, namespaces=None):
text = item.xpath(xpath, namespaces=namespaces)[0].text
if text is not None:
text = text.encode('utf-8')
return text
def open(self, printformat="<a href={fpath}>{title} - {subtitle}</a>, {pubdate}{space}"):
r = requests.get(self.url)
r.encoding = 'utf-8'
print "<meta charset='utf-8'/>"
root = etree.fromstring(r.text.encode('utf-8'))
items = root.xpath('//item')
for item in items:
title = self._getText(item, 'title')
pubDate = item.xpath('pubDate')[0].text
guid = item.xpath('guid')[0].text
subtitle = self._getText(item, 'itunes:subtitle',
namespaces={'itunes':"http://www.itunes.com/dtds/podcast-1.0.dtd"})
print printformat \
.format(fpath=guid, pubdate=pubDate,
title=title, subtitle=subtitle,
space='<br>')
class GMoneyParser(JdnyRssParser):
url = 'http://apple.radiorss.ytn.co.kr/news_new.xml'
def __init__(self):
super(GMoneyParser, self).__init__()
def main():
"""
:return:
"""
# parser = JdnyRssParser()
# print parser.open()
parser = GMoneyParser()
print parser.open(printformat="<a href={fpath}>{title}</a>, {pubdate}{space}")
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment