sunsexsurf

rss_parser_1

Apr 10th, 2020
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import feedparser
  2. import re
  3. import hashlib
  4.  
  5.  
  6. url = "http://www.cbr.ru/rss/RssPress"
  7. rss = feedparser.parse(url)
  8.  
  9. i_title = []
  10. last_hash = []
  11. j_href = []
  12. reg = re.compile(r'памятн', re.DOTALL)
  13.  
  14. for i in rss.entries:
  15.     # print(i)
  16.     if reg.findall(i.title):
  17.         # print(i)
  18.         i_title.append(i.title)
  19.         j_href.append(i.link)
  20.         last_hash = hashlib.md5(rss.entries[0].title + rss.entries[0].link).hexdigest()
  21.  
  22. news_list = [{"title": i_title, 'href': j_href, 'hash': last_hash}
  23.              for i_title, j_href, last_hash in list(zip(i_title, j_href, last_hash))]
  24.  
  25. # print(news_list)
  26. # print(rss.entries[0].title)
  27. # print(rss.entries[0].link)
  28.  
  29. # этот кусок нужно поместить в отдельный файл
  30.  
  31. rss_сheck_encode = feedparser.parse(url.encode('utf-8'))
  32.  
  33. this_hash = hashlib.md5(rss_сheck_encode.entries[0].title + rss_сheck_encode.entries[0].link).hexdigest()
  34. print(this_hash)
Advertisement
Add Comment
Please, Sign In to add comment