Last active
December 12, 2023 19:56
-
-
Save alexmill/9bc634240531d81c3abe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/python3.3 | |
from bs4 import BeautifulSoup as bs4 | |
import requests | |
import feedparser | |
import urllib.parse | |
def findfeed(site): | |
raw = requests.get(site).text | |
result = [] | |
possible_feeds = [] | |
html = bs4(raw) | |
feed_urls = html.findAll("link", rel="alternate") | |
if len(feed_urls) > 1: | |
for f in feed_urls: | |
t = f.get("type",None) | |
if t: | |
if "rss" in t or "xml" in t: | |
href = f.get("href",None) | |
if href: | |
possible_feeds.append(href) | |
parsed_url = urllib.parse.urlparse(site) | |
base = parsed_url.scheme+"://"+parsed_url.hostname | |
atags = html.findAll("a") | |
for a in atags: | |
href = a.get("href",None) | |
if href: | |
if "xml" in href or "rss" in href or "feed" in href: | |
possible_feeds.append(base+href) | |
for url in list(set(possible_feeds)): | |
f = feedparser.parse(url) | |
if len(f.entries) > 0: | |
if url not in result: | |
result.append(url) | |
return(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ranok I think no reason in particular