Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
list.sort() returning None
#1
Hi,

So I'm trying to code a script that uses requests and bs4 to go to https://news.ycombinator.com/news, and print out the most number of upvotes. I have a list of all the upvotes, but when a call print(articles_upvotes.sort()) it just prints None. Some thing happens if I save it to a variable and print the new variable. Here's the code:

from bs4 import BeautifulSoup
import requests

yc_web_page = requests.get("https://news.ycombinator.com/news").text
yc_soup = BeautifulSoup(yc_web_page, "html.parser")
articles = yc_soup.find_all(name="tr", class_="athing")

articles_text = []
articles_links = []
articles_upvotes = [score.getText().split()[0] for score in yc_soup.find_all(name="td", class_="subtext")]
articles_upvotes = [int(score) for score in articles_upvotes]

for article_tag in articles:
    article_text = article_tag.getText()
    article_link = article_tag.select("a")[0].get("href")
#    article_upvote = yc_soup.find_all(name="td", class_="subtext")[0].select("span.score")[0].text.split()[0]
#    print(article_upvote)

    articles_text.append(article_text)
    articles_links.append(articles_links)
#    articles_upvotes.append(article_upvote)

print(articles_text)
print(articles_links)
print(articles_upvotes.sort())
Reply


Messages In This Thread
list.sort() returning None - by SmallCoder14 - Mar-17-2024, 10:53 PM
RE: list.sort() returning None - by perfringo - Mar-18-2024, 05:48 AM
RE: list.sort() returning None - by DeaD_EyE - Mar-18-2024, 10:20 AM
RE: list.sort() returning None - by Pedroski55 - Mar-18-2024, 10:39 AM
RE: list.sort() returning None - by DeaD_EyE - Mar-18-2024, 08:16 PM
RE: list.sort() returning None - by SmallCoder14 - Mar-18-2024, 06:27 PM
RE: list.sort() returning None - by deanhystad - Mar-18-2024, 07:57 PM
RE: list.sort() returning None - by Pedroski55 - Mar-19-2024, 03:46 PM
RE: list.sort() returning None - by SmallCoder14 - Mar-19-2024, 09:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sort a list of dictionaries by the only dictionary key Calab 2 648 Apr-29-2024, 04:38 PM
Last Post: Calab
  returning a List of Lists nafshar 3 1,122 Oct-28-2022, 06:28 PM
Last Post: deanhystad
Photo a.sort() == b.sort() all the time 3lnyn0 1 1,347 Apr-19-2022, 06:50 PM
Last Post: Gribouillis
  list sort() function bring backs None CompleteNewb 6 4,210 Mar-26-2022, 03:34 AM
Last Post: Larz60+
  [solved] Sort list paul18fr 5 2,944 Aug-18-2021, 06:34 AM
Last Post: naughtyCat
  Sort List of Lists by Column Nju 1 12,217 Apr-13-2021, 11:59 PM
Last Post: bowlofred
  How to sort os.walk list? Denial 6 11,696 Oct-10-2020, 05:28 AM
Last Post: Denial
  2d List not returning DariusKsm 2 1,734 Sep-22-2020, 05:11 PM
Last Post: DariusKsm
  Need help returning min() value of list? edwdas 3 2,115 Nov-10-2019, 09:43 PM
Last Post: snippsat
  Converting to a list and sort tantony 6 3,276 Oct-07-2019, 03:30 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020