ArchThis Forum is for the discussion of Arch Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
This will run from tty, in case you are X/wayland broken, or running without GUI.
Only needs python3, urllib and xml.etree
Code:
#!/usr/bin/python
#Get the Arch Latest News
from xml.etree import ElementTree
from urllib import request
import re
#Make a user agent string for urllib to use
agent = ('Mozilla/5.0 (Windows NT 10.1; Win64; x64; rv:82.0) '
'Gecko/20100101 Firefox/82.0')
user_agent = {'User-Agent': agent}
class MakeList():
def __init__(self, url, fname):
#Get the xml to parse
req = request.Request(url, data=None, headers=user_agent)
html = request.urlopen(req)
tree = ElementTree.parse(html)
root = tree.getroot()
#Get tag data
tagA = root.findall('./channel/item/title')
tagB = root.findall('./channel/item/link')
tagC = root.findall('./channel/item/description')
tagD = []
#Append lines with separator
for a,b,c in zip(tagA,tagB,tagC):
tagD.extend([a.text, b.text, c.text, '_' * 70])
#Print and Write list to file
with open(fname, 'a') as f:
for line in tagD:
print('%s\n' % re.sub('<[^>]*>', '', line))
f.write('%s\n\n' % re.sub('<[^>]*>', '', line))
if __name__ == "__main__":
#Urls, log names
A = ('https://archlinux.org/feeds/news/', 'Arch_RSS.log')
B = ('file:///local/file/archfeed.xml', 'test.log')
#Choose RSS feed here
url, fname = A
MakeList(url, fname)
try:
from lxml import etree
print('Running with lxml.etree')
except:
try:
import xml.etree.ElementTree as etree
print('Running with ElementTree')
except:
print('Failed to import ElementTree')
...
Code:
tree = etree.parse(html)
But actually, I'd rather parse an RSS feed with Xidel:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.