Skip to content

Commit 8468cb8

Browse files
committed
refacto
1 parent 9d4218f commit 8468cb8

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

minet/reddit/scraper.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
ID_RE = re.compile(r"t1_(\w+)")
1616

1717

18+
# when missing a '/' at the end of an url, reddit will make a redirection and it will reduce by 2 the number of requests remaining
1819
def add_slash(url: str):
1920
path = url.split("/")
2021
if path[-1][0] == "?":
@@ -94,11 +95,11 @@ def get_current_id(com):
9495

9596

9697
def get_points(ele):
97-
scrapped_points = ele.select_one("[class='score unvoted']")
98-
score_hidden = ele.select_one("[class='score-hidden']")
98+
scrapped_points = ele.select_one(".score.unvoted")
99+
score_hidden = ele.select_one(".score-hidden")
99100
if not scrapped_points and not score_hidden:
100101
return "deleted"
101-
scrapped_points = ele.scrape_one("[class='score unvoted']", "title")
102+
scrapped_points = ele.scrape_one(".score.unvoted", "title")
102103
if not scrapped_points:
103104
return "score hidden"
104105
return scrapped_points
@@ -123,9 +124,9 @@ def data_posts(
123124
link,
124125
error,
125126
):
126-
author = post.scrape_one("a[class*='author']")
127-
if get_domain_name(link) == "reddit.com":
128-
link = ""
127+
author = post.scrape_one("a.author")
128+
if "reddit.com/" in link:
129+
link = None
129130
data = RedditPost(
130131
title=title,
131132
url=get_new_url(url),

0 commit comments

Comments
 (0)