summaryrefslogtreecommitdiffstats
path: root/minlobsters.py
blob: e383535aa3d347cf08fdd608ae7ae47bdd9fc3b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python3

import sys, getopt
import requests

from selectolax.parser import HTMLParser

def extract_lobsters(tag):
    base_url = f"https://lobste.rs/t/{tag}"
    r = requests.get(base_url, headers = {'User-agent': 'yourbot'})

    h = HTMLParser(r.text)
    items = h.css('ol.stories.list li') # Our parent CSS class, each article is in an li
    for i in items:
        score = i.css("div.score")[0].text() # .text() recovers the text between tags
        title = i.css("span.link a")[0].text()
        url = i.css("span.link a")[0].attrs['href'] # .attrs recovers attribute content (ie href here)

        print(f"\"{title}\" - {url} ({score})")

tag = "reversing"
extract_lobsters(tag)